1var given = moment("2018-03-10", "YYYY-MM-DD");
2var current = moment().startOf('day');
3
4//Difference in number of days
5moment.duration(given.diff(current)).asDays();
1// moment version => 2.13.0.
2const start = moment().subtract(1, 'days');
3const end = new Date();
4const actual = moment().subtract(1, 'hours');
5const test = moment(actual).isBetween(start, end);
6console.log(test);
7
8// moment version < 2.13.0.
9var startDate = new Date(2013, 1, 12)
10 , endDate = new Date(2013, 1, 15)
11 , date = new Date(2013, 2, 15)
12 , range = moment().range(startDate, endDate);
13range.contains(date);
1You can use one of the moment plugin -> moment-range to deal with date range:
2
3var startDate = new Date(2013, 1, 12)
4 , endDate = new Date(2013, 1, 15)
5 , date = new Date(2013, 2, 15)
6 , range = moment().range(startDate, endDate);
7
8range.contains(date); // false
1target.isBetween(start, finish, 'days', '()') // default exclusive
2target.isBetween(start, finish, 'days', '(]') // right inclusive
3target.isBetween(start, finish, 'days', '[)') // left inclusive
4target.isBetween(start, finish, 'days', '[]') // all inclusive
5