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.  Dates - Days Between 2 Dates

    Employee
    Posted 04-08-2015 14:34

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

    Originally posted by: BB2712

    Hello,

    We have two dates and would like to calculate the days between the two of them. Can we do something like the code below with the assistance of a formula?
    vDiffDays = (vDate1 ='ContDate'.SomeFormula())-(vDate2='ExpiresDate'.SomeFormula())
    emit *, vDiffDays

    Thanks,
    Brad


  • 2.  RE: Dates - Days Between 2 Dates

    Employee
    Posted 04-08-2015 14:36

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

    Originally posted by: stonysmith

    vDiffDays = dateSubtract(vDate1,vDate2)


  • 3.  RE: Dates - Days Between 2 Dates

    Employee
    Posted 04-08-2015 17:34

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

    Originally posted by: ckapashi

    Calculating difference between two dates in terms of years using dateSubtract provides inconsistent output. See below for examples:
    Example 1: Dt1 = 2007-10-22 and Dt2 = 2015-03-31. Using dateSubtract(d2,d1,"years") provides the output as 8 where the actual difference is 7 completed years.
    Example 2: Dt1 = 2007-02-12 and Dt2 = 2015-03-31. Using dateSubtract(d2,d1,"years") provides the correct output of 8 years.

    There is some inconsistency in terms of rounding up or down which I cannot figure out.
    How to fix this issue to get the correct full completed years between two dates?


  • 4.  RE: Dates - Days Between 2 Dates

    Employee
    Posted 04-08-2015 19:38

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

    Originally posted by: ryeh

    Oh, that's interesting. I also can't quite figure out how the rounding is done. But if you just care about the completed years between two dates, then see the following work-around. Basically, I create two new variables, t1 and t2 such that 1/31 becomes 131 and 10/01 becomes 1001. These don't really make much numerical sense, but we can use them to determine whether one date occurs before the other (not regarding the year). Based on that result, we can take Year2 - Year1 or Year2 - Year1 - 1.calcCompleteYears.brg