Last active
May 27, 2019 13:07
-
-
Save zaguiini/0bab7d39a1f9ed5bf19bab8bf6d400b2 to your computer and use it in GitHub Desktop.
Return the age given the parameters
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
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