Skip to content

Instantly share code, notes, and snippets.

@kitek
Created December 16, 2011 08:04
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 kitek/1485042 to your computer and use it in GitHub Desktop.
Save kitek/1485042 to your computer and use it in GitHub Desktop.
GetAge
var getAgeStr = function(dateString) {
var myDate = new Date(dateString),
now = new Date(),
month_of_birth=myDate.getMonth(),
day_of_birht=myDate.getDay(),
year_of_birth=myDate.getYear(),
now_month = now.getMonth(),
now_day = now.getDay(),
now_year = now.getYear(),
age = now_year - year_of_birth;
if (now_month < month_of_birth) {
age--;
} else if ((now_month == month_of_birth) && (now_day < day_of_birht)) {
age--;
if (age < 0) {
age = 0;
}
}
return age;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment