Answers for "how to get age in javascript"

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
2

calculate age js

const calAge = (date) => new Date(Date.now() - new Date(date).getTime()).getFullYear() - 1970;
Posted by: Guest on July-17-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language