Kamiikaze

Untitled

Aug 19th, 2018
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. // datepart: 'y', 'm', 'w', 'd', 'h', 'n', 's'
  2. Date.dateDiff = function(datepart, fromdate, todate) {
  3. datepart = datepart.toLowerCase();
  4. var diff = todate - fromdate;
  5. var divideBy = { w:604800000,
  6. d:86400000,
  7. h:3600000,
  8. n:60000,
  9. s:1000 };
  10. console.log("Diff " +diff);
  11. return Math.floor( diff/divideBy[datepart]);
  12. }
  13. //Set the two dates
  14. var y2k = new Date(2018, 8, 1);
  15. var today= new Date(2018, 8, 20);
  16. console.log('Weeks since the new millenium: ' + Date.dateDiff('d', y2k, today)); //displays 19
Advertisement
Add Comment
Please, Sign In to add comment