moment calculate days between two dates code example

Example 1: momentjs number of days between two dates

var given = moment("2018-03-10", "YYYY-MM-DD");
var current = moment().startOf('day');

//Difference in number of days
moment.duration(given.diff(current)).asDays();

Example 2: moment date difference in days

moment(new Date()).diff(moment(new Date()), 'days') // 0

Example 3: moment check days of difference between days

var a = moment([2007, 0, 29]);
var b = moment([2007, 0, 28]);
a.diff(b, 'days')

Tags:

Misc Example