Is there a way of comparing 2 dates without time with momentJS?
I've tried various formats, but can't seem to get it to work.
I have it working fine with dateTime:
var ExpiryDate = new Date("11/13/2014 11:13:00");
var daysDiff = moment(ExpiryDate).diff(moment(Date.now()), 'days');
I'm looking to get the result to be 14 days no matter what time of day.
Thanks
Date difference with Moment objects You can also create Moment objects and then calculate the difference: var admission = moment('{date1}', 'DD-MM-YYYY'); var discharge = moment('{date2}', 'DD-MM-YYYY'); discharge. diff(admission, 'days');
We can remove the time portion from a date with the startOf method. We pass in a date with the hour and minutes set into the moment function. Then we call startOf with the 'day' argument to get return a moment object with the time set to midnight of the same date.
js isBetween() Function. It is used to check whether a date is between a range in Moment. js using the isBetween() function that checks if a moment is between two other moments, optionally looking at unit scale (minutes, hours, days, etc).
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');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With