Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // datepart: 'y', 'm', 'w', 'd', 'h', 'n', 's'
- Date.dateDiff = function(datepart, fromdate, todate) {
- datepart = datepart.toLowerCase();
- var diff = todate - fromdate;
- var divideBy = { w:604800000,
- d:86400000,
- h:3600000,
- n:60000,
- s:1000 };
- console.log("Diff " +diff);
- return Math.floor( diff/divideBy[datepart]);
- }
- //Set the two dates
- var y2k = new Date(2018, 8, 1);
- var today= new Date(2018, 8, 20);
- console.log('Weeks since the new millenium: ' + Date.dateDiff('d', y2k, today)); //displays 19
Advertisement
Add Comment
Please, Sign In to add comment