0

First off thank you for taking the time to scroll through this.

I am basically a greenhorn when it comes to Java but I am working on a program that asks the user some basic info then sets a start date and then schedules service dates at bi weekly intervals between March and October from their start date.

For the start date variable, I simply set it up as:

STARTDATE = getDate();

to give the current date when the user signs up.

I have been sifting through my searches for days but I cannot figure out how to increment the service dates by 14 days to save my life.

I tried using SERVICEDATE = STARTDATE + (0, 14, 0); but I cant make sense of whats really happening here. Any ideas?

tutak
  • 1,120
  • 1
  • 15
  • 28
NixondisNRVA
  • 341
  • 1
  • 2
  • 9

3 Answers3

0

Use the common-lang library. It has a DateUtils class which can be used for this. Use it like this:

SERVICEDATE = DateUtils.addDays(STARTDATE, 14);
marcellsimon
  • 666
  • 7
  • 14
  • Thanks, that seems to work. Now how can I limit it so it wont accept dates between nov and feb? – NixondisNRVA May 29 '14 at 22:09
  • `Date yourdate = new Date(); Calendar calendar = new GregorianCalendar(); calendar.setTime(yourdate); int month = calendar.get(Calendar.MONTH); if(month >= Calendar.FEBRUARY && month <= Calendar.NOVEMBER){ }` – marcellsimon May 31 '14 at 08:44
0

Maybe have a look at this: Java getDate date-x days

They are subtracting days but I think it can be turned into adding days too.

Community
  • 1
  • 1
selena
  • 151
  • 13
0

I suggest you use Joda Library

Date STARTDATE = getDate();
DateTime stDate = new DateTime(STARTDATE);
//Date after 14 days
DateTime rsDate = stDate.plusDays(14);
tutak
  • 1,120
  • 1
  • 15
  • 28