calculate age by date of birth javascript code example
Example 1: javascript get age
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--;
}
return age;
}
Example 2: age calculator javascript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript program to calculate age</title>
</head>
<body>
</body>
</html>