wood burning stoves 2.0
The moose likes Java in General and the fly likes Get Dates between the given dates. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get Dates between the given dates." Watch "Get Dates between the given dates." New topic

Get Dates between the given dates.

Ranch Hand

Joined: Oct 09, 2003
Posts: 517
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 ?


God Gave Me Nothing I Wanted<br />He Gave Me Everything I Needed<br /> - Swami Vivekananda
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

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)
[ May 25, 2006: Message edited by: Paul Sturrock ]

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jean-Francois Briere
Ranch Hand

Joined: Mar 03, 2004
Posts: 101
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.

Mandar Max
Ranch Hand

Joined: Mar 14, 2006
Posts: 38
Try this: one of the simpler ways -

[ May 29, 2006: Message edited by: Mandar Max ]

"The trouble with doing something right the first time is that nobody appreciates how difficult it was!"
Ravindra Rawat
Ranch Hand

Joined: Dec 09, 2004
Posts: 34
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.

Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456

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,
I agree. Here's the link: http://aspose.com/file-tools
subject: Get Dates between the given dates.
It's not a secret anymore!