function getAge(dateString) {
var today = new Date();
var birthDate = new Date(dateString);
var age = today.getFullYear() - birthDate.getFullYear();
var m = today.getMonth() - birthDate.getMonth();
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
age--;
}
document.write(age);
}
getAge("01/20/2011")
This shows me 0 years, but i would like to show 10 Months and 9 Months until he his birthday comes 10/20/2011.
It often happens that you want to know the age a person would be on a specific date,
or the years, months and days between two dates.
If you do want the age as-of today, pass a single date or datestring argument.