Skip to content

Instantly share code, notes, and snippets.

@zaguiini
Last active May 27, 2019 13:07
Show Gist options
  • Save zaguiini/0bab7d39a1f9ed5bf19bab8bf6d400b2 to your computer and use it in GitHub Desktop.
Save zaguiini/0bab7d39a1f9ed5bf19bab8bf6d400b2 to your computer and use it in GitHub Desktop.
Return the age given the parameters
function getAge(month, day, year) {
const birthDate = new Date(year, month - 1, day)
const fromNow = new Date() - birthDate
const absoluteAge = new Date(fromNow).getFullYear()
// that's because timestamps starts from 1970, so
// we're getting relatively to that year
return Math.abs(absoluteAge - 1970)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment