Skip to content

Instantly share code, notes, and snippets.

@jrhorn424
Forked from gaand/age.js
Created October 6, 2015 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrhorn424/6107150a6e13cf887b2d to your computer and use it in GitHub Desktop.
Save jrhorn424/6107150a6e13cf887b2d to your computer and use it in GitHub Desktop.
var age = function age() {
var dob = new Date(this.dob);
var today = new Date();
var thisYear = today.getFullYear();
if (dob.getMonth() > today.getMonth() ||
dob.getMonth() === today.getMonth() &&
dob.getDate() >= today.getDate()) {
thisYear -= 1;
}
return thisYear - dob.getFullYear();
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment