I want to calculate the age based on the date of birth. I can do it easily for date format mm/dd/yyyy but when I try to do the same for dd/mm/yyyy I got age = NaN. Here is my code logic:
$('#DateOfBirth').datepicker({
onSelect: function (value, ui) {
var today = new Date(),
dob = new Date(value),
age = today.getFullYear() - dob.getFullYear(); //This is the update
$('#age').val(age);
alert(age);
},
//maxDate: "-16Y",
maxDate: maxDateVal,
showOn: "both",
buttonImage: "",
dateFormat: "dd/mm/yy",
changeMonth: true,
changeYear: true,
yearRange: '1920:c'
}).keydown(function (e) {
if (e.keyCode == 8 || e.keyCode == 46) {
$(e.target).val("");
} else {
e.preventDefault();
return false;
}
});