Monday, 10 May 2010

Age calculation JavaScript

var yourAge = currentYearYYYY - dobYearYYYY;

if ((currentMonth - 1 < dobMonth - 1) || (currentMonth - 1 == dobMonth - 1 && currentDay < dobDay))
yourAge --;

----------------------
The following script also will work, but it ignores leap years.

var yourAge = ((currentDate - DOB) / (24*60*60*1000 * 365)) //Remove 365 to calculate DateDiff

No comments:

Post a Comment