Forum Discussion

kumar25's avatar
kumar25
New Contributor II
2 years ago
Solved

Difference between 2 dates

Hi,

I have 2 dates, which are of localdatetime.

Date1 - 2023-08-13T14:17:00.000

Date2 - 2023-08-23T05:00:00.000

I am using the below expression find the difference between them, and i am getting value as 9.6131944444 expecting the value to be 10. Timestamp value to be exclude and dates only have to be compared.

 

(Date.parse($Date1.toString())-Date.parse($Date2.toString()))/(1000*60*60*24)

  • kumar25 - This will first strip off the portion of your string that contains the timestamp, then perform the date difference, and finally convert from milliseconds to day.

    (Date.parse($Date2.substr(0,10)) - Date.parse($Date1.substr(0,10)))
    / (1000 * 3600 * 24)

     Hope this helps!

3 Replies

  • Hello kumar25,

    You can try with the following expression in a Mapper Snap:

    Math.abs((Date.parse(Date.parse($Date1.toString()).toLocaleDateString())-
    Date.parse(Date.parse($Date2.toString()).toLocaleDateString()))
    /(1000*60*60*24))

    Try it, and let me know if this helps you!

    Regards,

    Aleksandar.

  • kumar25 - This will first strip off the portion of your string that contains the timestamp, then perform the date difference, and finally convert from milliseconds to day.

    (Date.parse($Date2.substr(0,10)) - Date.parse($Date1.substr(0,10)))
    / (1000 * 3600 * 24)

     Hope this helps!