We can use the isBetween
method to check if a date is between 2 dates.
For instance, we can write:
const compareDate = moment("15/02/2013", "DD/MM/YYYY");
const startDate = moment("12/01/2013", "DD/MM/YYYY");
const endDate = moment("15/01/2013", "DD/MM/YYYY");
const isBetween = compareDate.isBetween(startDate, endDate)
console.log(isBetween)
We create the compareDate
moment object that we want to check if it’s between startDate
and endDate
.
To do the comparison, we call isBetween
on compareDate
with startDate
and endDate
as the arguments.
Then isBetween
is false
since compareDate
isn’t between startDate
and endDate
.