Sometimes, we want to compare dates with the isSame() function in moment.js and JavaScript.
In this article, we’ll look at how to compare dates with the isSame() function in moment.js and JavaScript.
How to compare dates with the isSame() function in moment.js and JavaScript?
To compare dates with the isSame() function in moment.js and JavaScript, we call isSame with another moment object.
For instance, we write
const x = moment("28-02-2022", "DD-MM-YYYY");
const isSame = x.isSame(moment("28-02-2022", "DD-MM-YYYY"));
to call isSame with a moment object created with moment to check if it’s the same as x.
It should return true since x is the same as what we called isSame with.
Conclusion
To compare dates with the isSame() function in moment.js and JavaScript, we call isSame with another moment object.