Skip to content

Instantly share code, notes, and snippets.

@fabiobranis
Created June 18, 2019 17:49
Show Gist options
  • Save fabiobranis/c9efa3ef59ec452b14df22002b8dc3ca to your computer and use it in GitHub Desktop.
Save fabiobranis/c9efa3ef59ec452b14df22002b8dc3ca to your computer and use it in GitHub Desktop.
Simple function to calculate days difference - just a reminder
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