Sometimes, we want to compare only date in moment.js and JavaScript.
In this article, we’ll look at how to compare only date in moment.js and JavaScript.
How to compare only date in moment.js and JavaScript?
To compare only date in moment.js and JavaScript, we can use the isAfter
method.
For instance, we write
const isAfter = moment("2022-10-20").isAfter("2022-01-01", "year");
to call isAfter
on the moment("2022-10-20")
moment object to see if '2022-01-01'
is after moment("2022-10-20")
in terms of year.
It returns false
since '2022-10-20'
isn’t after '2022-01-01'
in terms of year.
Conclusion
To compare only date in moment.js and JavaScript, we can use the isAfter
method.