Last active
September 21, 2015 02:04
-
-
Save quangpd/0c4fe974c91324c3fbd2 to your computer and use it in GitHub Desktop.
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
/* Tính tuổi */ | |
function calculateAge (birthDate, otherDate) { | |
birthDate = new Date(birthDate); | |
otherDate = new Date(otherDate); | |
var years = (otherDate.getFullYear() - birthDate.getFullYear()); | |
if (otherDate.getMonth() < birthDate.getMonth() || otherDate.getMonth() == birthDate.getMonth() && otherDate.getDate() < birthDate.getDate()) { | |
years--; | |
} | |
return years; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment