File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Comparing two dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Comparing two dates" Watch "Comparing two dates" New topic

Comparing two dates

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 397
what is the best way to compare two dates? If you have two dates with a year, month and day, and you want to return "true" if date #1 is less than or == to Date #2.
Yosi Hendarsjah
Ranch Hand

Joined: Oct 02, 2003
Posts: 166
You can find the answer in the Java API documentation for java.util.Date class.
[ February 14, 2005: Message edited by: Yosi Hendarsjah ]
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
If you have them as individual integer values (3 each), you can skip creating a Date from them and just do it in an if test. You should reason out what that would look like, but I'll get you started.
  • Any date in 2004 is before every date in 2005.
  • In the same year, earlier months come before later months regardless of day of month.
  • ... (I gotta leave something for you to figure out!)

  • Senthil B Kumar
    Ranch Hand

    Joined: Feb 09, 2004
    Posts: 160

    [ February 21, 2005: Message edited by: kolkata prince ]

    Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
    Currently I Reside Here WEBlog
    David Harkness
    Ranch Hand

    Joined: Aug 07, 2003
    Posts: 1646
    CODE tags! CODE tags! CODE tags!

    Check out the "Instant UBB Code" buttons below the "Add Reply" button.
    I agree. Here's the link:
    subject: Comparing two dates
    It's not a secret anymore!