• 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

dates between two dates

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Is it possible in java to get all dates between two dates
for example
date1-> '01-11-2010'
date2-> '05-11-2010'
date3-> '10-11-2010'
Result :
'02-11-2010','03-11-2010','04-11-2010','06-11-2010','07-11-2010','08-11-2010','09-11-2010'
Can any one help me please..



 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can try exploring the Calendar class. It may not provide a direct way, but there are lot of methods which can help you achieve this.
 
Nisha Kala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply can you give me some brief idea about it
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can take the input- Start date and end date. So from Start date onwards- Keep adding 1 day to the date till the date is less than your end date. You can use- the add() method in the Calendar class.
 
Nisha Kala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can put all the Date objects into a List, and create an array from that List, if you wish.
 
Nisha Kala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply
I tried using list and am getting the missing dates..
But am not able to find the missing months..
example:
date1-> '11-11-2010'
date2->'02-01-2011'

I want to get all the dates between these two date
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nisha Kala wrote: ... But am not able to find the missing months.. ...


I don't know what you mean by Missing months. But using add() wil automatically increment the larger fields- Like month, year.
 
Nisha Kala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried add function.. am not able to it..
I got dates as a list of String..
 
Mohamed Sanaulla
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Nisha Kala wrote:I tried add function.. am not able to it..
I got dates as a list of String..



You have to be careful with the format of the dates. It will be easier if you have your startDate and endDate in java.util.Date and not in String. Otherwise you can use SimpleDateFormat and a correct pattern to convert them to Date instances. Once you have the Start and End dates in Date format. The next step would be:


Note that Calendar by default uses the following format: Mon Nov 22 12:24:44 IST 2010. You can check out how to use SimpleDateFormat here: http://download.oracle.com/javase/6/docs/api/java/text/SimpleDateFormat.html

Its always easier to convert from Date to String.
 
Nisha Kala
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you..
 
ice is for people that are not already cool. Chill with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic