aspose file tools*
The moose likes Java in General and the fly likes Generating a list of dates from a range Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Generating a list of dates from a range" Watch "Generating a list of dates from a range" New topic
Author

Generating a list of dates from a range

Harsha Pherwani
Greenhorn

Joined: Jul 11, 2005
Posts: 27
Hi All,
I have 2 dates as input (start and end). I need to generate a list of all dates in this range.

Does anyone have the code for this?
Any help is appreciated!

Thanks in adv.
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I'd use Calendar and its add method.


There is no emoticon for what I am feeling!
Edwin Dalorzo
Ranch Hand

Joined: Dec 31, 2004
Posts: 961
When you mean all dates in this range, you mean a date object for every single day between the two dates?
Harsha Pherwani
Greenhorn

Joined: Jul 11, 2005
Posts: 27
Yes Edwin. I wanted all dates (either as date objects or as strings) between 2 date objects.

I spent some time on it, doing it the hard way (long code but does it all), and then found an easy way to do it! Heres the easy code.

while (!calStart.equals(calalEnd)) {
// Add the date/cal to a list object
// add 1 day to the calStart.
}

I realise now, Calendar.add does it all for you! (The roll over between the month and the year.)

Thanks Jeff.
 
 
subject: Generating a list of dates from a range