View Full Version : Age Calculation Script error

06-10-2010, 04:20 PM

I am using the below code to calculate the age of a child from DOB. Criteria is as of 09/01/2010 (for the school year 2010-11). Even though the script seems to working fine in some cases the age calculations are wrong. Can some please tell what is wrong with the code.

For ex: DOB 12/20/1999 the age should be 10 as if 09/01/2010. However the age is calculated as 11 years.

Function Row_Inserting(rs)
If Not EW_DEBUG_ENABLED Then On Error Resume Next
DIM ChildAge, fromDate
ChildAge = DateDiff("d",rs("DOB"),fromDate)
If ChildAge <= (Cint("1095")) Then
CancelMessage="Your child is too young to attend our classes. Please register after your child has reached pre-K."
Row_Inserting = False
rs("Age")= DateDiff("YYYY",rs("DOB"),Date())
Row_Inserting = True
End If
End Function

Any pointers .. Thanks

06-10-2010, 09:26 PM
Do you want a javascript answer?
What you have posted is not javascript code.