View Full Version : DatePart Function


RACHNA
02-04-2000, 04:52 AM
I'm using the following code to compute Age based on Date of Birth. (i'm using 4 digit year)

Private Sub DOB_AfterUpdate()
Age.Value = DatePart("yyyy",[Now]) - DatePart("yyyy",[DOB])
End Sub

I'm getting bad results and realize I need to use month and day in the calculation.

Any ideas how?

Thanks!

CST9999
02-04-2000, 06:43 AM
Try this:
Days As Integer
Days = DateDiff("d", DOB, Date)
Days = Days / 365
Age.Value = Days

This should work for you.

[This message has been edited by CST9999 (edited 02-04-2000).]

RACHNA
02-04-2000, 07:45 AM
I tried this code and I still get the same results. So I tried the following:

Age = DateDiff("yyyy", [DOB], Now()) + _
Int(Format(Now(), "mmdd") < Format([DOB], "mmdd"))

Thanks!

[This message has been edited by RACHNA (edited 02-04-2000).]