Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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;
}
Comment

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!");
Comment

PREVIOUS NEXT
Code Example
Javascript :: generates a random rgb color number. 
Javascript :: add a route to a buttoin in angular 
Javascript :: express get full url 
Javascript :: jquery for table Show entries 
Javascript :: js get home url 
Javascript :: find min value in array javascript 
Javascript :: yeet 
Javascript :: Factorial of Number in Javascript using Recursive call in javascript 
Javascript :: javascript get utc time 
Javascript :: javascript detect space in string 
Javascript :: javascript image xss 
Javascript :: javascript get last day of month 
Javascript :: gitignore for angular 
Javascript :: react cloud foundry nginx 404 
Javascript :: how to get random boolean in javascript 
Javascript :: read file with deno 
Javascript :: window.location.href target blank 
Javascript :: javascript multiply arguments 
Javascript :: react native display flex center 
Javascript :: mongodb delete user 
Javascript :: Find channel discord js 
Javascript :: how to upgrade to react 18 
Javascript :: python dictionary to json 
Javascript :: jquery slidetoggle 
Javascript :: delete empty values from object js 
Javascript :: react-bootstrap nextjs 
Javascript :: js get url parameter 
Javascript :: email validatore regex 
Javascript :: click a link using jquery 
Javascript :: justifycontent react native flatlist 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =