cancel
Showing results for 
Search instead for 
Did you mean: 

Difference between 2 dates

kumar25
New Contributor II

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)

3 REPLIES 3

Aleksandar_A
Contributor III

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.

koryknick
Employee
Employee

@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!

kumar25
New Contributor II

Thanks @koryknick