Created
December 18, 2013 22:01
-
-
Save muratcorlu/8030607 to your computer and use it in GitHub Desktop.
Date difference with javascript
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
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