How do I calculate the age of a person who enters his date of birth in a YYYY/MM/DD format in a textbox?
This is what i've tried so far:
function OnClick() {
var txtDate = $("#txtDate").val();
var date1 = new Date();
date1.setFullYear(txtDate);
var d1 = date1.getFullYear();
var date2 = new Date();
var d2 = date2.getFullYear();
var age = d2 - d1;
document.getElementById("Diven").innerHTML = age;
}
I want to be able to calculate the exact age, so far I've only managed to do it by year using JQuery.
Help is appreciated