File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generating a list of dates from a range

 
Harsha Pherwani
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd use Calendar and its add method.
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you mean all dates in this range, you mean a date object for every single day between the two dates?
 
Harsha Pherwani
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic