Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

255
Views
get a date from age in javascript

I'm trying to show the date of birth when the user puts their age, date and month will be current, for this example 12 here present age

     var d = new Date();
     var newdate = (d.getFullYear()-12)+'-'+(d.getMonth()+1)+'-'+d.getDate();
     document.getElementById("age").value =newdate;

if I put the static values it shows on the HTML field (age)

document.getElementById("age").value ="2022-04-09";

but also if I try to change the input type from date to text then it shows the value

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Changing this as I miss understood the question, what you want to do is get the date from age.

Basic HTML Setup

<input id="age" type="text">
<input type="button" onClick="javascript:yearCalculate()" value="Calculate Birth Date">
<p>
You were born on: <span id="birthDate"></span>
</p>

And your javascript code

function yearCalculate() {
    // set Birthday and get todays date
  const birthDay = new Date();
  
  // get age 
  const ageYear = document.getElementById('age').value;

    // update year
  birthDay.setFullYear(birthDay.getFullYear() - ageYear);
  
  document.getElementById('birthDate').innerHTML = birthDay;
}

JSFiddle: https://jsfiddle.net/Lfrad2t6/

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!