Skip to content

Instantly share code, notes, and snippets.

@asmattic
Last active June 20, 2019 18:46
Show Gist options
  • Save asmattic/c4d3727ef4774c612a634989e2d26bd0 to your computer and use it in GitHub Desktop.
Save asmattic/c4d3727ef4774c612a634989e2d26bd0 to your computer and use it in GitHub Desktop.
Calculate Age
function getAge(DOB) {
var today = new Date();
var birthDate = new Date(DOB);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age = age - 1;
}
return age;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment