This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Dispalying random dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Dispalying random dates" Watch "Dispalying random dates" New topic
Author

Dispalying random dates

shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
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

Joined: Oct 27, 2005
Posts: 19654
    
  18


Just quickly written.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
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

Joined: Oct 11, 2007
Posts: 83
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

Joined: Sep 18, 2007
Posts: 189
Yes,exactly...
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19654
    
  18

It's not that different from my earlier code:

shalini gnana
Ranch Hand

Joined: Sep 18, 2007
Posts: 189
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

Joined: Oct 27, 2005
Posts: 19654
    
  18

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

Joined: Sep 18, 2007
Posts: 189
Thanks alot for your help..Now,I could able to display..
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Dispalying random dates
 
Similar Threads
Messagebox with Mouseevent
My scrollbars are not displaying
AWT Background Problem
Popup menu not responding with mouse event
mouse event for an array of object