I need to calculate if someone is over 18 from their date of birth using JQuery.
var curr = new Date();
curr.setFullYear(curr.getFullYear() - 18);
var dob =
You can remove the separate variable for DOB and collapse the if statement. The below code comes in at 165 characters:
var check = new Date();
check.setFullYear(check.getFullYear() - 18);
$(this).text((new Date("3/6/2009").getTime() - check.getTime() < 0)?"Under 18":"Over 18");
This will still keep the logic needed to deal with leap-years.