Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dispalying random dates

 
shalini gnana
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to display the dates between from date to todate...i.e.,if the from date is:2007/01/01 and todate is: 2007/03/01..I want the intermediate date 2007/02/01...I tried to display the dates...But Its not giving me the required(dates between from date and to date)....Its giving some random numbers..



Please help me...

[ November 23, 2007: Message edited by: shalini gnana ]
[ November 23, 2007: Message edited by: shalini gnana ]
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Just quickly written.
 
shalini gnana
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My question is not that...

I want to display the dates between from date to todate...i.e.,if the from date is:2007/01/01 and todate is: 2007/03/01..I want the intermediate date 2007/02/01...
 
Oggi Olli
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now, I don't know the general practice here at JavaRanch, but why don't you just post the relevant code and the relevant code only?

Anyway, say from date is 2007/01/01 and to date is 2007/01/15. Do you want the intermediate date to be 2007/01/07 or 2007/01/08?
 
shalini gnana
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes,exactly...
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not that different from my earlier code:

 
shalini gnana
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob,I don't want the date difference or the random date difference...
I want exactly the dates between the start date and the end date....
say, from date is 2007/01/01 and to date is 2007/01/05. I want the intermediate dates, 2007/01/02,2007/01/03,2007/01/04

Can you help me?
 
Rob Spoor
Sheriff
Pie
Posts: 20527
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, now I get it. You don't just want the middle date, but all dates in between.

When calculating with dates, always use Calendar instead of Date, since Calendar takes daylight savings time etc into account. If needed, use the add or roll methods, as these also handle new months and years as needed.


Also, "mm" in a date format is the number of minutes. You need "MM" for the month. For performance reasons you will want to declare and initialize that SimpleDateFormat before the loop, not inside.
[ November 23, 2007: Message edited by: Rob Prime ]
 
shalini gnana
Ranch Hand
Posts: 189
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks alot for your help..Now,I could able to display..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic