How to do a greater than or equal to with moments (moment.js) in javascript?
JavascriptDateDatetimeMomentjsJavascript Problem Overview
Basically, I want to do a myMoment >= yourMoment
. There is no myMoment.isSameOrAfter
and writing that out combining isSame
and .isAfter
is a bit lengthy.
What's the alternative? Convert moment to js date and use >=
to compare?
Javascript Solutions
Solution 1 - Javascript
You can use the isSameOrAfter
method in momentjs:
moment1.isSameOrAfter(moment2);
Solution 2 - Javascript
Solution 3 - Javascript
let A = moment('2020-01-02');
let B = moment('2020-01-01');
let C = moment('2020-01-03');
console.log(A.diff(B, 'days'));// => 1
console.log(A.diff(C, 'days'));// => -1
The supported measurements are years, months, weeks, days, hours, minutes, and seconds momentjs.com