Skip to content

Instantly share code, notes, and snippets.

@guiseek
Created March 30, 2020 01:45
Show Gist options
  • Save guiseek/8e6028a8cd67750958baac507153d49c to your computer and use it in GitHub Desktop.
Save guiseek/8e6028a8cd67750958baac507153d49c to your computer and use it in GitHub Desktop.
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