Skip to content

Instantly share code, notes, and snippets.

@VonSwirl
Last active November 25, 2019 09:54
Show Gist options
  • Save VonSwirl/6011f69143dece7431b5810a777412fc to your computer and use it in GitHub Desktop.
Save VonSwirl/6011f69143dece7431b5810a777412fc to your computer and use it in GitHub Desktop.
/**
* Compare 2 dates and to find days remaining.
* @param {Date} fromDate This is the starting point date .e.g Date.now()
* @param {Date} toDate A date set ini the future you wish to know how many day remain until.
* @returns {Number} Days remaining between the 2 dates.
* @license MIT https://opensource.org/licenses/MIT
* @author Jerome Hurley
*/
function daysUntilDate (fromDate, toDate) {
const oneDay = 24 * 60 * 60 * 1000
const firstDate = fromDate
const secondDate = toDate
const dayRemaining = Math.round(Math.abs((firstDate - secondDate) / oneDay))
// DEBUG console.log(dayRemaining)
return dayRemaining
}
export default daysUntilDate
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment