MomentJS Day diff dates only with the exception of time

Is there a way to compare two dates without time using jS moment?

I tried various formats, but can't make it work.

It works fine for me with dateTime:

var ExpiryDate = new Date("11/13/2014 11:13:00"); var daysDiff = moment(ExpiryDate).diff(moment(Date.now()), 'days'); 

I am looking to get a result of 14 days no matter what time of day.

thanks

+6
source share
1 answer

You can use the startOf function to remove the time components of both dates

 moment(ExpiryDate).startOf('day').diff(moment(Date.now()).startOf('day'), 'days'); 
+16
source

Source: https://habr.com/ru/post/977645/


All Articles