Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function timeBetweenDates (dateTo, dateFrom) {
// get total seconds between the times
let delta = Math.abs(date_future - date_now) / 1000
// calculate (and subtract) whole days
let days = Math.floor(delta / 86400)
delta -= days * 86400
// calculate (and subtract) whole hours
let hours = Math.floor(delta / 3600) % 24
delta -= hours * 3600
// calculate (and subtract) whole minutes
let minutes = Math.floor(delta / 60) % 60
delta -= minutes * 60
// what's left is seconds
let seconds = delta % 60
return {
days: days,
hours: hours,
minutes: minutes,
seconds: seconds
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.