0

COMPUTING BETWEEN DATES

Hello, 

I would like to compute the number of years between two dates. Any can help ? I also need to compute a delay to add to a starting date. Example : starting date + 3 years...

Best regards

5 replies

null
    • Birger_H
    • 5 yrs ago
    • Reported - view

    –––
    (year('Date2') - year('Date1')) - if month('Date2') < month('Date1') or (month('Date2') = month('Date1') and day('Date2') < day('Date1')) then 1 else 0 end
    –––

    Birger

    • Raphael_Vieira_de_Matos
    • 5 yrs ago
    • Reported - view

    Birger, 

    Thanks for your prompt reply.

    In Belgium, for a lease contract, we have to end the contract the day before the year. For example, 1/1/2019 to 31/12/2019. Even though your code is correct on the logical point of view, on the juridical point of view is not correct. We need to change the "then 1 else 0" by " then 0 else -1".

    Thanks a lot for your help ! Have a nice day...

    • Jorg
    • 5 yrs ago
    • Reported - view

    Hi Raphael, 

    Please try it with this one: 

     

    (year('Date2') - year('Date1')) - if month('Date2') < month('Date1') or (month('Date2') = month('Date1') and day('Date2') < day('Date1') - 1) then 1 else 0 end

    Best, Jörg

    • Raphael_Vieira_de_Matos
    • 5 yrs ago
    • Reported - view

    Jörg, 

    Thanks for the message but your answer is the same as the Birger's answer... ;-)

    • Jorg
    • 5 yrs ago
    • Reported - view

    Hi Raphael, 

    No, the last part is different ;)

    There is a -1 in the brackets before the last then

    Best, Jörg

Content aside

  • 5 yrs agoLast active
  • 5Replies
  • 1348Views