Answers for "how to calculate the age in javascript"

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;
}
Posted by: Guest on May-25-2020
5

javascript work out age from date of birth

// To calculate age:
var year_born = prompt("Please enter your date of birth:", "Type here");
var d = new Date();
var n = d.getFullYear();
function getAge(birthYear){
	var currentDate = new Date();
    var currentYear = currentDate.getFullYear();
    age = currentYear - birthYear;
    return age;
}
calculatedAge = getAge(year_born);
alert("Hello, " + "you are " + calculatedAge + " years old!");
Posted by: Guest on November-03-2020
0

age calculator javascript

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>JavaScript program to calculate age</title>
</head>
<body>

</body>
</html>
Posted by: Guest on March-19-2020

Code answers related to "how to calculate the age in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language