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 :: gettype js 
Javascript :: payload too large nodejs 
Javascript :: console.log color 
Javascript :: jquery confirm delete massege 
Javascript :: popup alert in flutter 
Javascript :: react-native-checkbox in a loop 
Javascript :: base64 PayloadTooLargeError: request entity too large 
Javascript :: Add Tailwind CSS to Svelte 
Javascript :: owl-carouselslide vertical 
Javascript :: moment date difference in days 
Javascript :: query selector click event 
Javascript :: vue call function every x seconds 
Javascript :: js push into array if item exist 
Javascript :: javascript create matrix 
Javascript :: loop through object element names javascript 
Javascript :: cors header missing vue api gateway 
Javascript :: fakepath 
Javascript :: new fabric canvas set width 
Javascript :: how to align placeholder in react native 
Javascript :: random choice js array 
Javascript :: adonis hook 
Javascript :: react scroll to top 
Javascript :: iterate over filelist javascript 
Javascript :: find a value in an array of objects in javascript 
Javascript :: public class NameOf { public static String nameof<T(Expression<Func<T name) { MemberExpression expressionBody = (MemberExpression)name.Body; return expressionBody.Member.Name; } } 
Javascript :: js random minus 
Javascript :: jquery check if iframe is loaded 
Javascript :: convert number to array javascript 
Javascript :: dm someone by id discord.js 
Javascript :: stack implementation in javascript using array 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =