calculate age js
const calAge = (date) => new Date(Date.now() - new Date(date).getTime()).getFullYear() - 1970;
calculate age js
const calAge = (date) => new Date(Date.now() - new Date(date).getTime()).getFullYear() - 1970;
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!");
age calculator javascript
function calculate_age(dob) {
var diff_ms = Date.now() - dob.getTime();
var age_dt = new Date(diff_ms);
return Math.abs(age_dt.getUTCFullYear() - 1970);
}
console.log(calculate_age(new Date(1982, 11, 4)));
console.log(calculate_age(new Date(1962, 1, 1)));
age calculator javascript
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>JavaScript program to calculate age</title>
</head>
<body>
</body>
</html>
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us