Answers for "javascript function to calculate age from date of birth entered in a text box"

2

javascript calculate age given date string

function getAge(dateString) {
   var ageInMilliseconds = new Date() - new Date(dateString);
   return Math.floor(ageInMilliseconds/1000/60/60/24/365); // convert to years
}
console.log(getAge('1997-04-23'));
Posted by: Guest on May-31-2021
13

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

Code answers related to "javascript function to calculate age from date of birth entered in a text box"

Code answers related to "Javascript"

Browse Popular Code Answers by Language