Am I missing something in the following jQuery code?
var dob = $(\'#date\').val();
if(dob != \'\'){
var today = new Date();
var dayDiff = Math.ceil(t
$('#date').val()
returns the string '1988-04-07'
. You need to parse it into an actual number.
dob = new Date(dob);
var today = new Date();
var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
$('#age').html(age+' years old');
As @esqew points out, you also need to change id="#date"
to id="date"
.