Skip to content

Instantly share code, notes, and snippets.

@iksnae
Created July 30, 2019 17:45
Show Gist options
  • Save iksnae/8db553e8a842e9524b6672714ffbce1c to your computer and use it in GitHub Desktop.
Save iksnae/8db553e8a842e9524b6672714ffbce1c to your computer and use it in GitHub Desktop.
Determine days between 2 dates with moment.js
let moment = require("moment")
let now = moment()
let otherDate = moment([2019, 6, 28])
let daysBetween = now.diff(otherDate, 'days')
let lessThanWeek = daysBetween <= 7
console.log(`${now} vs ${otherDate}` )
console.log(`Has it been less than a week? ${lessThanWeek?"YES":"NO"}. It's been ${daysBetween} days.`)
// Output:
// Tue Jul 30 2019 10:42:44 GMT-0700 vs Sun Jul 28 2019 00:00:00 GMT-0700
// Has it been less than a week? YES. It's been 2 days.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment