moment diff 2 dates code example

Example 1: moment diff

const dateDifference = moment(date1).diff(moment(date2))

Example 2: moment date difference in days

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

Example 3: moment diff

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

Example 4: moment js date between two dates

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