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

260
Views
obtener una fecha de edad en javascript

Estoy tratando de mostrar la fecha de nacimiento cuando el usuario pone su edad, la fecha y el mes serán los actuales, para este ejemplo 12 aquí la edad actual

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

si pongo los valores estáticos que muestra en el campo HTML (edad)

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

pero también si trato de cambiar el tipo de entrada de fecha a texto, muestra el valor

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

0

Cambiando esto porque no entendí la pregunta, lo que quieres hacer es obtener la fecha de la edad.

Configuración básica de HTML

 <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>

y tu codigo javascript

 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!