Skip to content

Instantly share code, notes, and snippets.

@kevinylu
Last active July 5, 2018 05:55
Show Gist options
  • Save kevinylu/46b550eafbc730fa2463095b5f51d99e to your computer and use it in GitHub Desktop.
Save kevinylu/46b550eafbc730fa2463095b5f51d99e to your computer and use it in GitHub Desktop.
Javascript count total days between two date values
var startDate = new Date('Tue Jul 10 2018 00:00:00');
console.log('startDate:' + startDate);
var currentDate = new Date(new Date().setHours(0, 0, 0, 0));
console.log('currentDate:' + startDate);
var ONE_DAY = 1000 * 60 * 60 * 24;
var date1_ms = startDate.getTime();
var date2_ms = currentDate.getTime();
var difference_ms = Math.abs(date1_ms - date2_ms);
var dateCount = Math.round(difference_ms / ONE_DAY);
console.log('dateCount:' + dateCount);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment