Is Between2.9.0+

  1. //From 2.13.0 onward
  2. moment().isBetween(moment-like, moment-like);
  3. moment().isBetween(moment-like, moment-like, String);
  4. moment().isBetween(moment-like, moment-like, String, String);
  5. // where moment-like is Moment|String|Number|Date|Array
  6. //2.9.0 to 2.12.0
  7. moment().isBetween(moment-like, moment-like);
  8. moment().isBetween(moment-like, moment-like, String);
  9. // where moment-like is Moment|String|Number|Date|Array

Check if a moment is between two other moments, optionally looking at unitscale (minutes, hours, days, etc). The match is exclusive. The first two arguments will be parsed as moments, if not already so.

  1. moment('2010-10-20').isBetween('2010-10-19', '2010-10-25'); // true
  2. moment('2010-10-20').isBetween('2010-10-19', undefined); // true, since moment(undefined) evaluates as moment()

If you want to limit the granularity to a unit other than milliseconds, pass the units as the third parameter.

  1. moment('2010-10-20').isBetween('2010-01-01', '2012-01-01', 'year'); // false
  2. moment('2010-10-20').isBetween('2009-12-31', '2012-01-01', 'year'); // true

Like moment#isSame, moment#isBefore, moment#isAfter any of the units oftime that are supported for moment#startOf are supported formoment#isBetween. Year, month, week, isoWeek, day, hour, minute, and second.

Version 2.13.0 introduces inclusivity. A [ indicates inclusion of a value. A ( indicates exclusion.If the inclusivity parameter is used, both indicators must be passed.

  1. moment('2016-10-30').isBetween('2016-10-30', '2016-12-30', null, '()'); //false
  2. moment('2016-10-30').isBetween('2016-10-30', '2016-12-30', null, '[)'); //true
  3. moment('2016-10-30').isBetween('2016-01-01', '2016-10-30', null, '()'); //false
  4. moment('2016-10-30').isBetween('2016-01-01', '2016-10-30', null, '(]'); //true
  5. moment('2016-10-30').isBetween('2016-10-30', '2016-10-30', null, '[]'); //true

Note that in the event that the from and to parameters are the same,but the inclusivity parameters are different, false will preside.

  1. moment('2016-10-30').isBetween('2016-10-30', '2016-10-30', null, '(]'); //false

If the inclusivity parameter is not specified, Moment will default to ().