Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.43 KB | None | 0 0
  1. var _MS_PER_DAY = 1000 * 60 * 60 * 24;
  2.  
  3. // a and b are javascript Date objects
  4. function dateDiffInDays(a, b) {
  5. // Discard the time and time-zone information.
  6. var utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
  7. var utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
  8.  
  9. return Math.floor((utc2 - utc1) / _MS_PER_DAY);
  10. }
  11.  
  12. console.log(dateDiffInDays(new Date("12/2/2012"), new Date()) + 1);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement