View Full Version : Calculating age from 2 dates


lesley
01-04-2002, 07:09 AM
This is probably really simple but I'm having difficulty in calculating a subjects age from the interview date and their date of birth. I want to automatically display their age so that it can be carried onto another form to eliminate various questions.

I was trying to do this in visual basic but couldn't quite figure it out from the help display of DateDiff

Please help

Thaks

Harry
01-04-2002, 07:57 AM
What format do you want the answer? Only years or years and months ......

lesley
01-04-2002, 08:11 AM
year only should be fine, I really only need to know if they are less than or equal to 56 years of age

Harry
01-04-2002, 08:20 AM
Easy way:
Age = Int((Now()-DOB)/365.25)

Harry
01-04-2002, 08:25 AM
OR :!!

If DateAdd("y", 57, Birthday) < Now then
MsgBox "Has passed 57th birthday"
else
msgbox "Young enough"
end if

R. Hicks
01-04-2002, 03:09 PM
Being you are wanting the "age at the date of interview" ... not the "age based on todays date" .... try this:

DateDiff("yyyy", [DOB], [IDate]) + ([IDate] < DateSerial(Year([IDate]), Month([DOB]), Day([DOB])))

"DOB" should be the "Date of Birth" information and "IDate" should be the "Interview Date" information.

HTH
RDH

[This message has been edited by R. Hicks (edited 01-04-2002).]