fork download
  1. var firstPostDate = "2013-05-11T19:47:01+00:00"
  2. var thisPostDate = "2016-08-24T00:29:04+00:00"
  3.  
  4. var _MS_PER_DAY = 1000 * 60 * 60 * 24;
  5. var _MS_PER_YEAR = _MS_PER_DAY * 365;
  6.  
  7. function dateDiffMs(a, b) {
  8. var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
  9. var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
  10.  
  11. return utc2 - utc1;
  12. }
  13.  
  14. function msToDays(ms){
  15. return Math.floor(ms / _MS_PER_DAY);
  16. }
  17.  
  18. function msToYears(ms){
  19. return Math.floor((ms / _MS_PER_YEAR) * 100) / 100;
  20. }
  21.  
  22. var dateDifference = dateDiffMs(new Date(firstPostDate), new Date(thisPostDate));
  23.  
  24. console.log("It was " + msToYears(dateDifference) + " years (" + msToDays(dateDifference) + " days) since you last posted this.");
Success #stdin #stdout 0.06s 26456KB
stdin
Standard input is empty
stdout
It was 3.29 years (1201 days) since you last posted this.