Skip to content

Instantly share code, notes, and snippets.

@DavidWells
Last active March 12, 2021 13:53
Show Gist options
  • Save DavidWells/636e49b3d1835eb4eac77ccfb74c6de7 to your computer and use it in GitHub Desktop.
Save DavidWells/636e49b3d1835eb4eac77ccfb74c6de7 to your computer and use it in GitHub Desktop.
Get difference between two dates. Number of days between unix timestamps
var numDaysBetween = function(d1, d2) {
var today = d2.getTime() / 1000
console.log('today', today)
var diff = Math.abs(d1 - (d2.getTime() / 1000));
console.log('diff', diff)
return diff / (60 * 60 * 24);
};
var d1 = 1497294888; // June 12, 2017
var d2 = new Date(); // Today
numDaysBetween(d1, d2);
@Xcalytoe
Copy link

Xcalytoe commented Aug 8, 2020

Awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment