Created
March 30, 2020 01:45
-
-
Save guiseek/8e6028a8cd67750958baac507153d49c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
export function getAge(birthday: Date, date = new Date()) { | |
let age = date.getFullYear() - birthday.getFullYear(); | |
const m = date.getMonth() - birthday.getMonth(); | |
if (m < 0 || (m === 0 && date.getDate() < birthday.getDate())) { | |
age--; | |
} | |
return age; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment