Skip to content

Instantly share code, notes, and snippets.

@AdamLJohnson
Created September 10, 2013 16:23
Show Gist options
  • Save AdamLJohnson/6511876 to your computer and use it in GitHub Desktop.
Save AdamLJohnson/6511876 to your computer and use it in GitHub Desktop.
This function returns age when given a DOB.
//This function returns age when given a DOB. getAge(DOB)
//You can also get the age on a given date. getAge(DOB, onDate)
function getAge(d1, d2) {
d2 = d2 || new Date();
var diff = d2.getTime() - d1.getTime();
return Math.floor(diff / (1000 * 60 * 60 * 24 * 365.25));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment