Win a copy of Microservices Testing (Live Project) this week in the Spring forum!
    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
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

How to check a date is within range of dates ?

 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Hi All,

I have a date for example 2007/10/04 in YYYY/MM/DD format,
and start date as 2008/08/12(YYYY/MM/DD),
end date as 2008/08/19(YYYY/MM/DD).

How to check wheather this date 2007/10/04 falls between 2008/08/12 and 2008/08/19?

Thanks & Regards,
Deepak
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
One way to do this would be:

1. Parse all those strings with dates into Date objects using SimpleDateFormat
2. Use the before() and/or after() methods of class Date to compare the Date objects
 
Ranch Hand
Posts: 266
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I presume these date's are represented as Strings. If so, parse them to java.util.Date [1] objects using the (inherited) parse(String) method from the java.text.SimpleDateFormat [2] class.
Now you have three Date objects and you can see if one of them lies in between the other two dates by using Date's before(Date) and after(Date) methods.

Good luck.

[1] http://java.sun.com/j2se/1.4.2/docs/api/java/text/SimpleDateFormat.html
[2] http://java.sun.com/j2se/1.4.2/docs/api/java/util/Date.html
 
Deepak Kumar
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Thanks a lot, Its working!!!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
...
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

nin hat wrote:


Please check your private messages for an important administrative matter

I am sorry, but I have edited out your post. Please do not hijack other people's threads to ask your questions.
You can post your problem by starting a new thread.
UseOneThreadPerQuestion

Also, please do take out time to read http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic