• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Generating a list of dates from a range

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd use Calendar and its add method.
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic