Created
July 30, 2019 17:45
-
-
Save iksnae/8db553e8a842e9524b6672714ffbce1c to your computer and use it in GitHub Desktop.
Determine days between 2 dates with moment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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