Created
June 18, 2019 17:49
-
-
Save fabiobranis/c9efa3ef59ec452b14df22002b8dc3ca to your computer and use it in GitHub Desktop.
Simple function to calculate days difference - just a reminder
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
const daysBetween = ( date1, date2 ) => { | |
//Get 1 day in milliseconds | |
let one_day=1000*60*60*24; | |
// Convert both dates to milliseconds | |
let date1_ms = date1.getTime(); | |
let date2_ms = date2.getTime(); | |
// Calculate the difference in milliseconds | |
let difference_ms = date2_ms - date1_ms; | |
// Convert back to days and return | |
return Math.round(difference_ms/one_day); | |
} | |
let a = new Date(2019,3,22) | |
let b = new Date(2019,5,18) | |
console.log(daysBetween(a,b)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment