Compute age Html

Whing Dela Cruz
Whing Dela Cruz used Ask the Experts™
on
Hi experts, how to compute the age using Js?

<script>
function sAge()
{
var sDate = "Friday, February 14, 1975"
var s = Now;
age = (sdate - s)
alert(age)
}
</script> 

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Distinguished Expert 2017
Commented:
var sDate = "Friday, February 14, 1975";


function ageCalc(arg){
var a=Date.parse(arg);
var s =Date.now();
var age;
ageDiffer = (s-a);
age=Math.floor((ageDiffer/86400000)/365);
return age;
}
console.log(ageCalc(sDate)+' years old');

Open in new window


Ouputs 42 years old.

Author

Commented:
Its working perfectly sir, Thank you once again!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial