Skip to content

Instantly share code, notes, and snippets.

@muratcorlu
Created December 18, 2013 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save muratcorlu/8030607 to your computer and use it in GitHub Desktop.
Save muratcorlu/8030607 to your computer and use it in GitHub Desktop.
Date difference with javascript
var date1 = new Date(2010, 6, 17);
var date2 = new Date(2013, 12, 18);
var diff = new Date(date2.getTime() - date1.getTime());
// diff is: Thu Jul 05 1973 04:00:00 GMT+0300 (EEST)
console.log(diff.getUTCFullYear() - 1970); // Gives difference as year
// 3
console.log(diff.getUTCMonth()); // Gives month count of difference
// 6
console.log(diff.getUTCDate()); // Gives day count of difference
// 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment