Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Get Dates between the given dates.

 
MInu
Ranch Hand
Posts: 517
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, i am trying to do someting like this:

A user choose a initial and a final date. For example:

Ini: 07/07/2004 Fin: 11/07/2004

Ok, what i need to do, is to get all dates between this two above. The answer needs to be...

08/07/2004 09/07/2004 10/07/2004

Is there a method that do this for me, i ve looking for but not finding ?

Thanks...
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no method, but it should be easy enough. Have a look at the Calendar class and in particular its add(int field, int amount)
method.
[ May 25, 2006: Message edited by: Paul Sturrock ]
 
Jean-Francois Briere
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also to convert the string "07/07/2004" into a java.util.Date object (or the reverse) have a look at the java.text.SimpleDateFormat class.

Regards
 
Mandar Max
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this: one of the simpler ways -


[ May 29, 2006: Message edited by: Mandar Max ]
 
Ravindra Rawat
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the time component of dates that your have generated if that is used in your application.

If your date range has has dates when daylight saving is turned on or off then time component changes while you increment date using calendar API, e.g 24:00 in your code may change to 23:00 or 01:00.

Cheers
Ravindra
 
Jan Groth
Ranch Hand
Posts: 456
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,

i had almost the same problem and solved it quite comfortably with the joda-time framework. just google for it, it's a sourceforge project. these guys did a great job, specially when it comes to daylight saving time and leap-years...

hope it helps,

greetings from world-cup crazy berlin,
jan
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic