Sometimes, we want to check if date between dates with Moment.js and JavaScript.
In this article, we’ll look at how to check if date between dates with Moment.js and JavaScript.
How to check if date between dates with Moment.js and JavaScript?
To check if date between dates with Moment.js and JavaScript, we can use the isBetween
method.
For instance, we write
const compareDate = moment("15/02/2022", "DD/MM/YYYY");
const startDate = moment("12/01/2022", "DD/MM/YYYY");
const endDate = moment("15/01/2022", "DD/MM/YYYY");
const isBetween = compareDate.isBetween(startDate, endDate, "days", "()");
to call compareDate.isBetween
with startDate
and endDate
to check is compareDate
is between startDate
and endDate
when comparing days.
The last argument is the inclusivity value, which specifies we compare exclusively.
We can also use '(]'
for right inclusive, '[)'
for left inclusive, or '[]'
for all inclusive.
Conclusion
To check if date between dates with Moment.js and JavaScript, we can use the isBetween
method.