Skip to Content
avatar image
Former Member

how to get difference between todays date and the last longin date

Hi ,

Plz help me to solve this problem -

My requirement -

1. I have to find the difference between a past date say d1 and today's date say d2.

2. If the difference between theses two dates is more than or equalto 6 months , then perform some logic .

Date Last = user.lastModified();

Date Current = new Date(System.currentTimeMillis());

int diff= Current.compareTo(Last);

How to proceed after this step .

I have done to this extent .

Please help me to get it resolved soon

Thanks in advance !!.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

4 Answers

  • Best Answer
    avatar image
    Former Member
    Sep 26, 2008 at 11:36 AM

    Hi,

    1. I have to find the difference between a past date say d1 and today's date say d2.

    2. If the difference between theses two dates is more than or equalto 6 months , then perform some logic .

    Date Last = user.lastModified();

    Date Current = new Date(System.currentTimeMillis());

    int diff= Current.compareTo(Last);

    
    Date Last = user.lastModified();
    Date Current = new Date(System.currentTimeMillis());
    
    long diff = current.getTime() - last.getTime();
    long days = (diff / (1000 * 60 * 60 * 24));
    
    if( days >= 180) 
      Your logic goes here
    
    

    Regards

    Ayyapparaj

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 26, 2008 at 11:02 AM

    hi

    u just type this code and see

    Date startDate1 = new GregorianCalendar(1996, 02, 14, 14, 00).getTime();

    Date endDate1 = new Date();;

    long diff = endDate1.getTime() - startDate1.getTime();

    Regards

    Ruturaj

    Edited by: Ruturaj Inamdar on Sep 26, 2008 1:20 PM

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 26, 2008 at 12:23 PM

    hi!

    Date Last = user.lastModified();

    Date Current = new Date(System.currentTimeMillis());

    //convert the difference in number of days

    long diffDays = (Last - Current ) / (24 * 60 * 60 * 1000);

    if( diffDays >= 180)

    {

    //perform your logic

    }

    thanks

    vishal

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Sep 27, 2008 at 07:29 PM

    Hi..........thanks a lot for the response

    the solution worked.

    Add comment
    10|10000 characters needed characters exceeded