10 lines
313 B
JavaScript
10 lines
313 B
JavaScript
function getAge(dateString) {
|
|
var today = new Date();
|
|
var birthDate = dateString;
|
|
var age = today.getFullYear() - birthDate.getFullYear();
|
|
var m = today.getMonth() - birthDate.getMonth();
|
|
if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
|
|
age--;
|
|
}
|
|
return age;
|
|
} |