In versions 2.9 + there is an isBetween function, but it is exclusive:
var compareDate = moment("15/02/2013", "DD/MM/YYYY"); var startDate = moment("12/01/2013", "DD/MM/YYYY"); var endDate = moment("15/01/2013", "DD/MM/YYYY");
There is a workaround ...
x.isBetween(a, b) || x.isSame(a) || x.isSame(b)
... which is logically equivalent !(x.isBefore(a) || x.isAfter(b))
In version 2.13 , the isBetween function has a fourth optional parameter, inclusivity .
Use it as follows:
target.isBetween(start, finish, 'days', '()') // default exclusive target.isBetween(start, finish, 'days', '(]') // right inclusive target.isBetween(start, finish, 'days', '[)') // left inclusive target.isBetween(start, finish, 'days', '[]') // all inclusive
More units to consider: years, months, days, hours, minutes, seconds, milliseconds
Note: units are still optional. Use null as the third argument to ignore units, in which case milliseconds are the default granularity.
Visit official docs
ThisClark Apr 7 '15 at 15:45 2015-04-07 15:45
source share