28 April 2007

Age calculate by Birthday


if(crmForm.all.birthdate.DataValue != null)
{
var now = new Date();
var birthday = crmForm.all.birthdate.DataValue;
var monthdif = now.getMonth() - birthday.getMonth();
if(monthdif > -1)
crmForm.all.new_age.DataValue = now.getYear() - birthday.getYear();
else
crmForm.all.new_age.DataValue = now.getYear() - birthday.getYear() - 1;
}

1 comment:

Anonymous said...

Hi Jim

Im glad I found your blog! Saved me lots of time. However I think you need to use getFullYear() instead of getyear(). Getyear () cannot pick up full year information. It only picks up 50 for year 1950, for example. This lead to the age to be incorrect. Somehow it can pick up 2008 for year 2008 though.

Regards
Shan