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 :: javascript regular expression for alphanumeric 
Javascript :: difference between e.preventdefault and e.stoppropagation and return false 
Javascript :: getting the current url in node js 
Javascript :: import json javascript 
Javascript :: image touchable opacity react native 
Javascript :: javascript Validating the Phone Number 
Javascript :: open link in new window chrome mac shortcut 
Javascript :: angular viewchild input element value 
Javascript :: navigate to route and refresh angular 6 
Javascript :: js array enclose all items with ' 
Javascript :: javascript sort chars in string 
Javascript :: get last day of month javascript 
Javascript :: set onclick javascript 
Javascript :: react after deployment givin nginx 404 
Javascript :: javascript random boolean 
Javascript :: random code js 
Javascript :: addeventlistener to button javascript 
Javascript :: jquery sort select options by text 
Javascript :: foreach nodejs 
Javascript :: find item in object js 
Javascript :: detect button click jquery 
Javascript :: npm react-dom 
Javascript :: react map array limit 
Javascript :: how to use current data in javascript 
Javascript :: Use Recursion to Create a Countdown 
Javascript :: javascript change long digit ot k,m 
Javascript :: decet wheter react app in development or production 
Javascript :: javascript check if all capital letter 
Javascript :: mui theme remove shadow 
Javascript :: document.getelementbyid.onclick 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =