0

How to get age from dob efficiently? Will you give me more information?

function myFunction(){
   var d = new Date();
   var year = new Date(document.getElementById('dob').value);   
   var age = d.getFullYear() - year.getFullYear();
   document.getElementById('age').value = age;    
  }
<input type="date" id="dob" placeholder="Date of birthday" onchange="myFunction()"><br/>
   <input type="text" id="age">
  • 3
    Possible duplicate of [Calculate age in JavaScript](http://stackoverflow.com/questions/4060004/calculate-age-in-javascript) – Scott Sauyet Mar 21 '17 at 18:39

1 Answers1

0

I recommend using Moment.js [https://momentjs.com/] lib for all calculation of time and date

Have fun

pery mimon
  • 7,713
  • 6
  • 52
  • 57