javascript calculate age

Solutions on MaxInterview for javascript calculate age by the best coders in the world

showing results for - "javascript calculate age"
Niklas
21 Oct 2020
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}
Nico
04 May 2016
1const calAge = (date) => new Date(Date.now() - new Date(date).getTime()).getFullYear() - 1970;
2
Lisa
15 Feb 2016
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!");
Cristina
02 Feb 2016
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
Emilie
08 Jun 2018
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
Giacomo
04 Nov 2017
1calculate Age using Javascript
queries leading to this page
get age in years jscalc age in jsexpress js find ageget birth date from age jsjavascript calculate age from date of birth in months age 2b 2b javascriptjavascript get age from date of birthcalculate age from dob jsjs date of birthage calculator javascript w3schoolsage find with date of birth jsage calculator using java scriptfind how old with function jsfrom age to date of birth javascriptcalculating age javascriptage caclulator in jscheck specific age based on day jsjavascript age functionusing javascript to calculate age from database iso datejavascript code for displaying date birthdayjavascript birthday dateage calculator by year jsis there a function in javascript to calculate age in datebirth year javascripthow to find age of person using javascriptcalculate age from year of birth in javascripttime and date stamp to calculate aging javascripthow to calculate age next birthday javascriptjavascript ageages based on dates vuejsfinding out age javascripthow to calculate a person 27s day of birth from date in javascriptjs calculate ageshow birthdate in jsage calculator using javascripthow to print age date of birth in javascripthow to count age by date of birth in vuejshow to get year from dob in javascriptjavascript calculate someone 27s agejs according to bday agecalculate age from date of birth nodejscalculate age using date object jshow to get the age of given birth date in javascript 22calculate age javascript htmlcalculate age of person in javascriptfind age jshow to return age year in number in jsget age according two date jsjavascript calculate age fromid numberhow to get your birthday in jscalculating age from years inside array in javascriptcalculating age from date of birth in javascriptage calculator js from date of birth textbocage from date javascripthow to calculate age from date of birth in htmlcalculate age javascript with birthdate and current datecalculate date of birth from age in javascript and return only valueage of java scriptjs calculate age from birthdatejavascript how to calculate age by date of birthhow to calculate current age from date of birth in javascript only yearshow to check age in javascriptfunction to calculate age from date of birth in javascriptget exact age from data jscalculate age today in dayjshow to find age in days javascriptjs get age from birth datehow to check age with date of birth in javascripthow to make age calculate in javascriptcalculate age using date jsjavascript calculating age from date of birthfind age from date jsage calculator html css javascriptjavascript realtime calculate age from dateread a number in javascript and return age how to calculate age from date of birth in html5javascript calculate age between two datesnew date javascript agefind age from dob jscalculate age from date of birth in node jshow to code a check age function in javascripthow to know the age with the date of birth nodegetting age automatically when given date of birth javascriptfunction that get age in javascriptget age jsjavascript get agecalculate age from date jsfind age in jsjavascript age in yearsdetermine someons exact age with date object jscheck age number in javascript function htmljavascript date to agecalculate age from date of birth in javascriptjavascript calculate age from date of birthclaculate age from birthdate in javascriptget age javascriptjs calculate age from date of birthhow to check age validation in javascriptjavascript function to calculate age in yearage calculation javascript functionage calculation using date of birth in javascriptjavascript age from birthdatejavascript calculate age todays dateconvert date of birth to age in javascriptdetect age from date jscalculating age in javascript through date functionhow to make a age shower in javascriptdate of birth javascriptjavascript calc agevar age 3d 7bperson 7dbitrthdate javascriptcalculate age function javasciptget age methd javascriptjavascript calculate age based on date of birthhow to check age with date of birth with out using javascript predefine functionshow to use date to calculate date of birth javascriptwrite a function that take birth date and returns age in years 2c months and days jshow to calculate age in javascriptage calculation formula in javascriptsimple age calculator in htmlcheck certain age javascripthow to calculate age javascriptjs maths for working out if date of birth is greater or less than an agejavascript get exact age from datejavascript display current agejs get agejavascript calculate age from year of birthbirth date via age in jshow to calculate birth year from age in javascriptwrite a function that determines the given age that person is in javascriptenter date of birth for age calculate in javascript fromage calculator javascript getdate 28 29javascript age calculatorgestational age calculator by javascriptcalculate birthdate javascripthow to calculate age in es6 javascriptjavascript find age from birthdateget year with a birth date to methods javascriptdate born to now jscalculate age with todays age node jsget date of birth from age javascriptjavascript age difference validationes6 calculate ageget date of birth in age javascriptcalculate age in javascriptage by date javascriptage mwthod jscalcualting age from date pf birth javascriptwrite a function in js that calculates the born dayhow to culculate age according to date of birth jscalculate age based on date of birth in javascriptcalculate your date of birth javascriptget age from dob javascriptcalculate age from date jswork out birthday from current date reacthow to determine the age and days in javascript to a given date of birthhow to calculate age by values entered javascriptnode js age countingjs get age from date stringdate of birth how to generate age jsjavascript calculate someones agecalculate age from date of birthcalculate age from birthdate javascriptjs calsulacte 1 2 of my agejavascript get birthdaycalculate age from date of birth in htmlget age show date of birth jshow to calculate age from date of birth jshow to validate age using javascripthow to make a date of birth from javascriptjavascript calculate birth datecalculating age using javascripthow can i show my birth days in javascripthow to calculate age from date parse valuesreturn age from date jshow to calculate age with jsjs calculate age by datecalculate birthdate from age jsfind the age in javascriptcalculate age from dob in javascriptjs input date of birth calcage range calculation based on date of birth vuejsjavascript get birthdate with minimum age find age from date of birth javascriptcalculate age based on date of birth using javascripthow to calculate the age in javascriptcalculate age formula javascriptjs get age from datesfunction to calculate age and days in javascriptconvert date to age javascriptcalculate date of birth from age in javascriptjavascript calc my agejavascript calculate age in years 2c months daysage calculator logic in javascriptcalculate age js datesage in javascriptdate to age jscalculate exact age from date of birth javascriptjavascript function take birthdate and return age convert date of birth to age with javascriptcheck age in javascripthow to calculate a person 27s age with javascriptnode js calculate agecalculate age using form jscreate 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 calculate age in javascript from date of birthjavascript calculate age with valuesjavascript to calculate age from date of birthage calculate jscalculate age using date of birth javascriptage javascriptjavascript date of birth to ageget age from date of birth htmlcalculate age by date of birth in javascriptget the age from date of birth javascriptcalculate age from date of birth node jshow to calculate age from date of birth in javascriptjavascript to calculate user 27s age 2c based on dob in javascriptjavascript calculate born datejavascript function to calculate age from date of birth entered in a datepickerjs date from birthjs birthday to ageage calculate using jsjavascript html get ageget current age by birthday jsjavascript work out age from date of birthcalculate age by birthdate jscalculate dob from age in javascriptjavascript to calculate age based on dobcalculate age given date in jscheck age based on date of birth in javascriptjs age calculatorage calculator onlinemariage age javascriptfrom date to age function javascriptconvert year into age jqueryjavascript function to display ageage calulator in javascriptage calculat birthdate jsage calculation jsage calculation javascriptcalculate age from dob javascriptget your age using dates jscalculate age from birthdate jscalculate age by birthday javascriptdob jsjs check for ageget age with day jsget age from date of birth javascriptjavascript function to calculate age in daysmethod to calculate age from date of birth in javascriptcalculate age from date of birth in javascript hijriconvert age in years return age in days javascriptcheck age number in javascript functionjavascript to validate ageage calculator in javascriptget birth year from age in javascriptage calculatorget years by age jsjavascript code to calculate age in yearsget age from date in javascriptage calculator from date of birth javascriptjavascript calc age from datecalculating age from dob in javascriptwhat is the javascript code for an age calculator bot clacualting age in jsbirthdate to age javascripthow to validate age in form using javascriptcalculate age in jsdisplay age jsjs calculate age functioncalculate age using date of birth in javascripthow to check age jsaccurate age calculator javascriptcalculate age from date of birth javascriptjavascript age calculatorcalculate age in javascript formage from date function javascriptauto calculate age in javascriptage calculation in jshow age calculate online by date of birth using javascriptnew date age calculator jsfunction acceptintomovie 28age issupervised 29 javascriptcalculate age javascript date birthcalculate age with month from date of birth in jsjavascript counting age from datecalculate age from id number javascriptcalculate date of birth from age javascripthow to get age from date of birth using javascriptage check javascriptcalculate age in days javascriptcalculate age from new date jshow to calculate age in days in javascript using returndate js calculage agecalculate age by date of birth javascriptsimple age calculator in jsjavascript calculate age in daysjavascript function to calculate age from date of birthcalculate current age java scriptget your age javascriptjs age from dateage and date of birth html javascripthow to find age from date of birth in jsjavascript compute ageget date of birth javascripthow to calculate age usog javascript date and timeconvert date to age in javascriptcount age javascripthow to get age from date of birth in javascriptjavascript calculate age from date stringage calculator using javasscripthow to find age in express jshow to get age from birth year in jsjavascript age from date of birthhow to find age javascriptdayjs calculate agefind age javascriptautomatically calculate age from date of birth javascriptfind age bt date stringjavascript funtion to calculate age above 18date to age and age to dob in jshow to get a person 27s day of birth and convert it to name on jsjs calculater agehow to get current age from date of birth javascriptget age from dob jsconvert age to days from birthday javascriptjavascript date of birth calculatordate counting by age in javascript from inputjavascript calculate age by date of birthhow to calculate age in jsfind age from date of birth jsjavascript how do i findout my current agejavascript age calculator appjavascript get age by birth datehow to add age to a birthdate jsjavascript calculate age from birthdateget age js with mouthsjavascript date get ageget age from date jsdate to age calculator in javascriptcalculate age javascriptangualr check minor age dateavascript calculate age by date of birthcalculate age from date of birth dayjsfunction to check age in javascript calculate age function javascriptjavascript age calculationcalculate age with javacsript datehow to count age from date of birth in htmlage calculater jscalculate age from dob html javascriptw3schoolsget age from date of birth jscalculate age with javascripthow to find someone 27s date of birth from date in javascriptjs function to calculate agejavascript count ageage calculate formula jshow to calculate the age from date of birth in javascriptdate of birth node jsstack overflow age jshow to get age in javascriptage calculator js codejs how to calculate your agehow to get the age of given birth date in javascriptcalculate age javascript html domfind out age from date of birth in javascriptjavascript calculate age differencehow to make program about age calculator in javascriptage calculator from date of birth javascript precisecheck age jsjs work out age from dobage calculator js javascript get the age from datecompare value to the date 28 29 to obtain age javascriptjs calculate age from date of birth cleanconvert age to days using form jsjavascript function for age calculationhow to calculate date of birth from age in javascriptcalculate age from date of birth jsbirthdate from age in jsjs born ageshow your age jsjavascript age from datecalculate age from date of birth using datepicker in jqueryage calculatoe in jsfunction to calculate age in javascriptinput your dob 28date 29 through prompt for example date is 2224 22write a function calculate age that takes your birthday in the format dd 2fmm 2fyyyy and return your agejavascript 27 27 3e function to calculate age from date of birth entered in a datepickertakes the age in years and returns the age in days javascriptdage calcxulator javascriptjs calculate age from datehow to create age calculator in javascriptjs calc agecalculate the age from date of birth in javascriptcalculate age from dob html javascriptsave age in javascriptcalculate age based on the year of birth using javascripthow to find age today in javascriptstore birth year in variable javascriptcalculate age from date javascriptage calculator is jsyear calculator for age code in javascriptcalc common age jsjavascript birthday calculatorcalculate age by date of birth javascripfind age from date of birth in javascriptage calculate in javascriptdate of birth using jsnumber day determinate age on earth jscalculate age with timestamp in jsget age from ist javascriptcalcage 2820 29 javascriptjavascript function calculate age date birthhow to get the age of given birth date in an object javascriptjavascript calculate age in years from date of birthuse javascript to get agejavascript calculate age from dateyear of birthday calculator javascriptget age from date javascriptget age dayjsage calculator javascript codeget age according to date jsget age from date of birthformat age in age group in javascriptage calculate in jshow to calculate age from date of birth javascriptget age from current date javascriptconvert age into date of birth jsjs get age from datecalculate age at certain year in javascriptjavascript work out how old someone is based on their birthdayjavascript get current agedate to age javascriptget age in javascriptcalculate age from date of birth 2c jqueryage method jsjs birth ageget age from year jsjavascript calculate afejavascript age of person based on birth datejavascript calculate age from birth datecheck age javascriptcalculate age acurate javascriptprogram to calculate age from date of birth in javascript how to find age in javascriptcalculate age jsjavascript calculate ageexact age calculator javascriptconvert age in years to age in days javascriptjavascript current agejs agejavascript register date of birth to agejs age functionhow to calculate your age for future years jsget age from now and birth date javascriptget age with dayjsjavascript calculate age from integercalculate age function javascript w3schoolsjavascript get age from datejs to calculate ageget age by date of birth in java scriptcalculate age by date of birth and todays date using javascriptjavascript calculate age using arrow functionhow to calculate your birthday using javascriptget a person 27s age with two javascript datesjavascript birth yearhow pass date of birth in function in jsbirthday to age javascriptget year of birth from age javascriptget age by string value in javascriptagehow to find age from date of birth timestamp in javascriptage calculator in jsjavascript 27s agejs dob to yearsjs get age from birthdatecalclate age in jsget date of birth from user html jscalculate age from string date of birth in javascriptget new age javascripthow to use a user input date to calculate age in java scripthow to determine age by dateof birth javascriptage calculation in javascriptbirthdate javascriptage function in javascriptjs date to ageage calculator javascriptcalculate age with jshow to get age from date of birth javascriptcalculate age in days using date of birth in javascripthow to find age by date of birth in javascriptjavascript calculate age given date string js date of birthenter date of birth for automatic age calculate in javascript from fieldnode js age countingage calculation in html and javascriptage field in javascriptjavacript age from datecacluate age in javascriptjavascript date of birthcalculate age values given in javascriptmethod to compute age from birth year jshow to calculate the age in java scriptget exact age javascriptjs date calculate agejavascript age calculator from date of birthjs know how old someone isprogramme js calculate agecalculate age from dob html javascript w3schoolshow do i calculate someone 27s age based on a datetime type birthday 3f in jsjs calculate age from date in real timehow to turn age to birth date in jshow to calc age jshow to calculate age based on date of birth in javascriptcalculate age by birth date javascriptbrthday function javascriptcalculate age in years javascripthow get current age in reacthow to make an age calculator in javascriptcalculate age dayjshow t o calculate age from current date in javascriptjavascript get age from dobjavascript to calculate user 27s age 2c based on dobget age javascriptjavascript calculate date of birth age from birth date jsjs how to calculate agejavascript calculate age in yearsjavascript code to calculate age from date of birthcalculate age from birthdate on jscalculate age from date of birth in nodejshow to count age by date of birth in vuejs site 3astackoverflow comjavascript calculate age