Created
September 10, 2013 16:23
-
-
Save AdamLJohnson/6511876 to your computer and use it in GitHub Desktop.
This function returns age when given a DOB.
This file contains 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
//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