Last active
June 20, 2019 18:46
-
-
Save asmattic/c4d3727ef4774c612a634989e2d26bd0 to your computer and use it in GitHub Desktop.
Calculate Age
This file contains hidden or 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
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