aspose file tools
The moose likes Java in General and the fly likes Date Comparision Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Date Comparision" Watch "Date Comparision" New topic
Author

Date Comparision

sreedhar Lackka
Ranch Hand

Joined: Jul 05, 2008
Posts: 154
Hi All,

Thanks in advance.

I would like to do the date comparision in Java without any caluculations like days*hours....

Just want to know whether the two selected days difference is below one year.
Please advice and give me some example code.



Thanks & Regards,
Sreedhar
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

So, you have two Date objects, let's say date1 and date2, where date1 is before date2, and you want to know if the time between them is less than one year.

One way to do this with Java's standard date and time API is like this:

  • Get a Calendar object and set it to the value of date2.
  • Use Calendar's methods to subtract one year.
  • Check if the date that the calendar is set to is before date1. If this is true, then the time between date1 and date2 is less than one year.


  • Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
    Scala Notes - My blog about Scala
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Date Comparision
     
    Similar Threads
    Getting Next date using Java
    increment date by 6 days
    Date comparision in java
    BETWEEN statement in jboss-ql
    problem with the compareto method in date class