javascript work out age from date of birth

Solutions on MaxInterview for javascript work out age from date of birth by the best coders in the world

showing results for - "javascript work out age from date of birth"
Caterina
30 Jun 2019
1function getAge(dateString) 
2{
3    var today = new Date();
4    var birthDate = new Date(dateString);
5    var age = today.getFullYear() - birthDate.getFullYear();
6    var m = today.getMonth() - birthDate.getMonth();
7    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) 
8    {
9        age--;
10    }
11    return age;
12}
Andrea
21 Nov 2016
1const calAge = (date) => new Date(Date.now() - new Date(date).getTime()).getFullYear() - 1970;
2
Roberto
31 Jan 2021
1// To calculate age:
2var year_born = prompt("Please enter your date of birth:", "Type here");
3var d = new Date();
4var n = d.getFullYear();
5function getAge(birthYear){
6	var currentDate = new Date();
7    var currentYear = currentDate.getFullYear();
8    age = currentYear - birthYear;
9    return age;
10}
11calculatedAge = getAge(year_born);
12alert("Hello, " + "you are " + calculatedAge + " years old!");
Timeo
02 Jan 2021
1function calculate_age(dob) { 
2    var diff_ms = Date.now() - dob.getTime();
3    var age_dt = new Date(diff_ms); 
4  
5    return Math.abs(age_dt.getUTCFullYear() - 1970);
6}
7
8console.log(calculate_age(new Date(1982, 11, 4)));
9
10console.log(calculate_age(new Date(1962, 1, 1)));
11
12
Greta
05 Oct 2016
1function Person(dob) {
2  // [1] new Date(dateString)
3  this.birthday = new Date(dob); // transform birthday in date-object
4  
5  this.calculateAge = function() {
6    // diff = now (in ms) - birthday (in ms)
7    // diff = age in ms
8    const diff = Date.now() - this.birthday.getTime(); 
9    
10    // [2] new Date(value); -> value = ms since 1970
11    // = do as if person was born in 1970
12    // this works cause we are interested in age, not a year
13    const ageDate = new Date(diff); 
14    
15    // check: 1989 = 1970 + 19
16    console.log(ageDate.getUTCFullYear()); // 1989
17    
18    // age = year if person was born in 1970 (= 1989) - 1970 = 19
19    return Math.abs(ageDate.getUTCFullYear() - 1970);
20  };
21}
22var age =new Person('2000-1-1').calculateAge();
23console.log(age); // 19
24
queries leading to this page
check age jsjavascript calculate age in years 2c months dayscalculating age using javascripthow age calculate online by date of birth using javascriptget age in years jsjavascript realtime calculate age from datehow to get age from date of birth using javascriptjavascript get age by birth datejavascript get age from dateget age show date of birth jsget age from date jscalculate age javascriptjavascript date of birth to agejavascript funtion to calculate age above 18calculate age from dob in javascriptsimple age calculator in htmlhow to check age in javascripthow to calculate age in es6 javascriptfunction to calculate age in javascriptcalculate age from date of birth jsjs age functionjs birth agevar age 3d 7bperson 7dconvert date to age javascriptcalculate the age from date of birth in javascriptjavascript calculate age by date of birthhow to calculate age from date of birth jshow to culculate age according to date of birth jsage calculate in jsjavascript get birthdate with minimum age convert age in years to age in days javascripttakes the age in years and returns the age in days javascriptjs calculate age from birthdateage calculator html css javascriptcalculate age from date of birth using datepicker in jqueryhow to calculate age javascriptnumber day determinate age on earth jshow to count age from date of birth in htmlhow to know the age with the date of birth nodejs age calculatorhow can i show my birth days in javascriptes6 calculate ageconvert date to age in javascriptget date of birth from user html jscalculate age from dob html javascriptjavascript get exact age from datejs get age from dateget age with dayjsjavascript compute agecalculate age in years javascriptjavascript calculate age todays datejavascript calculate age in years from date of birthage from date function javascriptcalculate age with timestamp in jsjavascript get current ageclaculate age from birthdate in javascriptcalculate age using date jsdate of birth node jsjavascript counting age from dateage calculation formula in javascriptcalculating age javascriptjavascript work out age from date of birthjavascript age from date of birthusing javascript to calculate age from database iso dateage calculatoe in jscalculate dob from age in javascripthow to get year from dob in javascriptjavascript calculate age from date of birth in months age find with date of birth jsjs know how old someone isyear calculator for age code in javascripthow to calculate age by values entered javascriptget age from date in javascriptbirthday to age javascriptjavascript birthday calculatorcalculate age from date of birth in node jsget age from date of birth htmlage calculator from date of birth javascriptjavascript calculate age using arrow functionfind age from date of birth javascriptdate js calculage ageage calculator js from date of birth textbocjavascript calculate age from year of birthjavascript birth yearget age with day jscalculate age by birthday javascriptcalculate exact age from date of birth javascriptread a number in javascript and return age javascript get birthdaynew date age calculator jshow to make an age calculator in javascriptjavascript age from birthdatewrite a function that determines the given age that person is in javascriptage calculator using javascriptshow your age jscalculate age in javascript from date of birthfunction to calculate age from date of birth in javascripthow to find age in javascriptget age from current date javascriptcheck age javascriptjavascript function for age calculationcalculate age from year of birth in javascriptbirthdate to age javascriptjavascript to calculate age from date of birthage calculator logic in javascriptjavascript calculate age in yearsjavascript display current agehow to count age by date of birth in vuejs site 3astackoverflow comjavascript calc agejavascript code to calculate age from date of birthjavascript date get agejavascript get age from date of birthcalculate age dayjscalculate age from date of birth in javascriptfind age in jsfrom age to date of birth javascriptjs to calculate age js date of birthage caclulator in jsdate to age and age to dob in jsage calculate using jshow to find age from date of birth in jscalculate age by date of birth in javascriptjs calc ageage calculator in jsget age from dob jsjavascript to calculate user 27s age 2c based on dobget age according to date jsmethod to calculate age from date of birth in javascriptage method jshow to calculate age in jsmethod to compute age from birth year jsjavascript calculate age differencejavascript find age from birthdatecalculate age from birthdate on jsjavascript calculate born datefind out age from date of birth in javascriptnode js age countingdate to age jscalculate age using date of birth javascriptjs get agecalcualting age from date pf birth javascripthow to get the age of given birth date in javascripthow to get the age of given birth date in javascript 22javascript 27s agecalculating age from dob in javascriptage calculat birthdate jsjavascript calculate age with valuescalculate age in javascriptcalculate age formula javascriptconvert age to days from birthday javascriptget exact age from data jshow to calculate age next birthday javascriptjs calculate agestack overflow age jscalculate age from birthdate javascriptfind the age in javascripthow to find someone 27s date of birth from date in javascriptfrom date to age function javascriptnode js age countingjavascript calculate someone 27s ageaccurate age calculator javascriptjavascript count ageage 2b 2b javascriptcheck certain age javascriptjavascript calculate age in daysjavacript age from datecalculate age jsnew date javascript agecalculating age from years inside array in javascriptget new age javascriptcalculate age in days javascriptcalculate age of person in javascriptage calculator in javascripthow to calculate age from date of birth in htmlhow to calculate current age from date of birth in javascript only yearsformat age in age group in javascriptavascript calculate age by date of birthexact age calculator javascripthow to find age today in javascriptconvert age in years return age in days javascripthow to find age of person using javascripthow to calculate a person 27s age with javascriptget birth year from age in javascriptjavascript work out how old someone is based on their birthdayjs date of birthautomatically calculate age from date of birth javascriptcalculate age from date jsjavascript get age from dobget age from now and birth date javascriptcalculate age from new date jscalculate age using date object jsbrthday function javascriptjavascript date to agecheck age in javascriptsimple age calculator in jsjavascript age calculator appage calculator javascript codehow to find age in days javascripthow to determine age by dateof birth javascriptyear of birthday calculator javascriptage calculation in jsjs according to bday ageget age dayjsget age from date of birth jshow t o calculate age from current date in javascripthow to get current age from date of birth javascriptage calculator javascript w3schoolshow to get a person 27s day of birth and convert it to name on jscalculate age by date of birth javascripjs how to calculate agefind age javascriptjavascript calculating age from date of birthcalclate age in jscalc common age jsjs how to calculate your agehow to calculate age based on date of birth in javascriptjs born agecalcage 2820 29 javascriptstore birth year in variable javascriptjavascript calc age from datecalculate age from date of birth node jshow to check age with date of birth with out using javascript predefine functionsbirth year javascriptcalculate age based on the year of birth using javascriptjavascript age calculationdate to age calculator in javascriptcalculate date of birth from age in javascripthow to calculate birth year from age in javascriptcalculate age from dob html javascript w3schoolsage calculator by year jsjs get age from birthdatehow to make age calculate in javascripthow to calculate age with jsjavascript birthday dateget your age using dates jsage from birth date jsage calculatorcalculate current age java scripthow to get age from birth year in jsjavascript function calculate age date birthage mwthod jscalculate age with month from date of birth in jscheck age number in javascript functiondate of birth javascriptdetect age from date jscalculate age from date of birthage range calculation based on date of birth vuejsjavascript function to calculate age in daysjavascript calculate age from date stringbitrthdate javascriptcalculate age js datesage calculator onlinehow to check age with date of birth in javascriptjavascript to calculate age based on dobfind age from date of birth in javascriptjs get age from datesjavascript register date of birth to ageconvert date of birth to age in javascriptjavascript get agecalculate age based on date of birth using javascriptcalculate age with javacsript dateget age js with mouthsgestational age calculator by javascriptjs date from birthget age javascriptjavascript current ageage calculator js codecheck age based on date of birth in javascriptfunction that get age in javascriptjavascript code to calculate age in yearstime and date stamp to calculate aging javascriptcalculate age by birthdate jsis there a function in javascript to calculate age in datehow to calc age jscalculate age from date of birth in javascript hijrihow to calculate age in javascriptget age from date javascriptcalculate age from date of birth nodejsjavascript age of person based on birth datework out birthday from current date reactjavascript calculate age from birthdatejavascript calculate date of birth get age methd javascriptcalculate age with todays age node jsget age from date of birth javascriptget current age by birthday jsget the age from date of birth javascripthow to find age by date of birth in javascriptget date of birth in age javascriptfind age jscalculate age given date in jsage calculation javascriptget age by date of birth in java scriptcreate a javascript function with the name age 28 29 this function will take your date of birth as parameters and return your age in years js calculate age from dategetting age automatically when given date of birth javascripthow to check age validation in javascriptcalculate age based on date of birth in javascriptcalculate date of birth from age in javascript and return only valuehow to count age by date of birth in vuejsfind age from dob jsage calculator javascript getdate 28 29angualr check minor age datejs date to ageages based on dates vuejscalculate age from date of birth dayjscalculate age from string date of birth in javascriptage of java scripthow to get the age of given birth date in an object javascriptcalculate birthdate javascriptage calculater jsjavascript age calculator from date of birthwrite a function that take birth date and returns age in years 2c months and days jsjavascript function take birthdate and return age calculate age by birth date javascripthow to calculate your age for future years jsage calculate in javascriptjs calculate age from date in real timejavascript calculate age from datesave age in javascriptjavascript function to calculate age from date of birthwrite a function in js that calculates the born daybirthdate javascripthow to calculate the age in javascriptjavascript function to calculate age from date of birth entered in a datepickerjavascript function to display agecalculate age function javasciptjavascript html get agehow to check age jshow to calculate age from date of birth javascriptcheck specific age based on day jsjs get age from date stringage calulator in javascripthow to calculate your birthday using javascriptage calculator from date of birth javascript precisecalculate age from id number javascriptreturn age from date jshow to make program about age calculator in javascriptage calculate jshow to create age calculator in javascriptcount age javascriptget year of birth from age javascriptfind age from date of birth jsdayjs calculate ageconvert age into date of birth jsage calculation using date of birth in javascriptauto calculate age in javascriptcalculate age from date of birth in nodejscalculate age from date of birth in htmlget age from year jshow to find age javascriptfinding out age javascriptget exact age javascriptcalculate age javascript with birthdate and current dateage calculator js js dob to yearsdob jsenter date of birth for automatic age calculate in javascript from fieldfind age from date jscalculate age in days using date of birth in javascripthow to get age from date of birth in javascriptjs function to calculate agehow to calculate age from date of birth in javascriptjavascript date of birth calculatorage calculator using javasscripthow to add age to a birthdate jsdate of birth using jsenter date of birth for age calculate in javascript fromfunction to check age in javascript convert year into age jqueryhow to calculate a person 27s day of birth from date in javascriptuse javascript to get ageage calculator javascriptget years by age jshow to find age from date of birth timestamp in javascriptcalculate age from dob html javascriptw3schoolsagecheck age number in javascript function htmlcalculate age from date jsjs calculater agecalculating age in javascript through date functionget date of birth javascripthow do i calculate someone 27s age based on a datetime type birthday 3f in jsjs calculate age from date of birthcalculate age using form jsjavascript age calculatorage calculation javascript functionconvert age to days using form jshow to use date to calculate date of birth javascriptjs calculate age by dateage calculator using java scriptjavascript how to calculate age by date of birthcalculate age at certain year in javascriptage and date of birth html javascriptget date of birth from age javascriptage calculation in javascriptget age from date of birthjs birthday to agehow to make a date of birth from javascriptprogram to calculate age from date of birth in javascript mariage age javascriptage calculate formula jscalculate age using date of birth in javascriptjavascript date of birthjavascript calculate age from integerage calculator is jsjs date calculate agejs calculate age functiondetermine someons exact age with date object jsjavascript get the age from datewhat is the javascript code for an age calculator bot javascript age calculatorjavascript calc my agecalculate age function javascriptcalculate age in jscalculate age with javascriptage javascriptjavascript calculate ageconvert date of birth to age with javascriptclacualting age in jsdate born to now jscalculate your date of birth javascriptjs check for agecalculate birthdate from age jscompare value to the date 28 29 to obtain age javascriptcalculate age today in dayjshow to calculate age in days in javascript using returnprogramme js calculate ageage from date javascriptcalculate age values given in javascriptcalc age in jshow to get age from date of birth javascripthow to get age in javascripthow to get your birthday in jshow to code a check age function in javascriptget age by string value in javascriptget age javascriptjavascript age from datecalculate age acurate javascriptget age in javascriptcalculate age from dob jsget year with a birth date to methods javascriptcalculate age by date of birth and todays date using javascriptage function in javascriptjavascript ageshow birthdate in jscalculate age javascript date birthget age jsjavascript calculate age from date of birthcalculate age from date of birth javascriptjavascript age in yearshow to calculate age from date parse valuesbirth date via age in jsget age according two date jswrite a function calculate age that takes your birthday in the format dd 2fmm 2fyyyy and return your ageage in javascriptjs get age from birth datejavascript 27 27 3e function to calculate age from date of birth entered in a datepickerjavascript calculate afecalculate age by date of birth javascriptjs input date of birth calcjavascript age difference validationjavascript function to calculate age in yeardate of birth how to generate age jshow to calculate the age from date of birth in javascriptfind age bt date stringget your age javascriptdate to age javascriptnode js calculate agehow get current age in reactget age from dob javascripthow to turn age to birth date in jsinput your dob 28date 29 through prompt for example date is 2224 22how to calculate the age in java scriptjavascript calculate birth datehow to determine the age and days in javascript to a given date of birthage calculation jsjavascript calculate age based on date of birthfunction acceptintomovie 28age issupervised 29 javascripthow to return age year in number in jscalculate date of birth from age javascriptget birth date from age jscalculating age from date of birth in javascriptjavascript calculate age from birth datejs age from datejs work out age from dobfunction to calculate age and days in javascripthow to calculate age from date of birth in html5calculate age from date of birth 2c jqueryjavascript to calculate user 27s age 2c based on dob in javascriptjavascript age functioncalculate age with jsbirthdate from age in jsjs calculate age from date of birth cleanhow to print age date of birth in javascriptcalculate age from date javascriptget a person 27s age with two javascript datesjavascript calculate someones agecalculate age from birthdate jsjavascript work out age from date of birth