Skip to content

Instantly share code, notes, and snippets.

@quangpd
Last active September 21, 2015 02:04
Show Gist options
  • Save quangpd/0c4fe974c91324c3fbd2 to your computer and use it in GitHub Desktop.
Save quangpd/0c4fe974c91324c3fbd2 to your computer and use it in GitHub Desktop.
/* 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