I've calculated the age using setFullYear
and getFullYear
, as I only want to use the birth year to calculate age for fun, but it doesn't work
Here's the code I've tried so far, which I think should work. Please give me some pointers:
function Onclick()
{
var Text1 = $("#Text1").val();
var datetoday = new Date();
var today = datetoday.getFullYear();
var datebirthday = new Date();
datebirthday.setFullYear(Text1);
var birthday = datebirthday.getFullYear();
var age = today - birthday;
$("#txtAge").text(age);
}