LAE

Welcome to the LAE community!  Please feel free to start a discussion in the discussion tab or join in a conversation.

Discussions

Members

Resources

Events

 View Only
  • 1.  compare two date.

    Employee
    Posted 07-09-2014 23:21

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: rakhi

    how could i compare two date. for example i have the following fields,

    date1 date2
    22-02-2012 31-12-2010
    17-02-2012 15-05-2014
    17-02-2012 15-05-2014
    01-01-2012 03-04-2013
    01-01-2012 03-04-2013
    01-01-2012 03-04-2013
    31-03-2012 31-05-2013


    I want to compare (< or > or = ) between date1 and date2 and date2 is greater than date1 want to differenc between date1 and date 2 .
    Thanks in advance.


  • 2.  RE: compare two date.

    Employee
    Posted 07-10-2014 06:23

    Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.

    Originally posted by: stonysmith

    Let's assume that the two fields are strings. First you must convert them to dates:
    d1=date1.date("DD-MM-CCYY")
    d2=date2.date("DD-MM-CCYY")

    Then, to compare the two dates you can simply do this:
    if d1 > d2 then .....action.........

    To find out the difference between two dates:
    diff = dateSubtract(d1,d2)

    Lastly, if d1 (should be) the earlier of the two dates:
    if d1 > d2 then diff = dateSubtract(d2,d1) else diff = dateSubtract(d1,d2)

    However, that can also be done simpler with this:
    diff = abs(dateSubtract(d1,d2))