Last active
July 5, 2018 05:55
-
-
Save kevinylu/46b550eafbc730fa2463095b5f51d99e to your computer and use it in GitHub Desktop.
Javascript count total days between two date values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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