Skip to content

Instantly share code, notes, and snippets.

@toadkicker
Created February 14, 2014 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toadkicker/8996196 to your computer and use it in GitHub Desktop.
Save toadkicker/8996196 to your computer and use it in GitHub Desktop.
Calculate age from birthdate
function getAge(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
return age;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment