Hello!
How can I calculate age in years from a date of format YYYYMMDD to today. Is it possible using the Date() class?
Thank you.
EDIT:
I am looking for a better solution than the one I am using now:
var dob='19800810';
var year=Number(dob.substr(0,4));
var month=Number(dob.substr(4,2))-1;
var day=Number(dob.substr(6,2));
var today=new Date();
var age=today.getFullYear()-year;
if(today.getMonth()<month || (today.getMonth()==month && today.getDate()<day)){age--;}
alert(age);