View Full Version : Age Calculations


eyalco
04-13-2008, 11:20 AM
I'm having a problem with this age formula in the query :

AGE: DateDiff("yyyy",[birth_date],Date()) & " " & " years" & " " & "and" & " " & DateDiff("m",[birth_date],Date()) Mod 12 & " " & "months"

Need your help guys in 2 probs :
1. age calculated is not right.
2. need to compute what w'd be age on the sep 1st 2008 - how do I do it?

Appreciate your help.
Thanks.

RuralGuy
04-13-2008, 11:58 AM
Have you searched this forum (http://www.access-programmers.co.uk/forums/showthread.php?t=146787&highlight=age) yet?

raskew
04-13-2008, 12:00 PM
You need to rename your date field to something else since Date is the name of an Access function.

Try this:

Function fAge2(DOB As Date, dteEnd As Date) As Integer
'Inputs: 1) ? fAge2(#4/13/53#, #10/23/06#)
' 2) ? fAge2(#11/1/53#, #10/23/06#)
'Outputs: 1) 53
' 2) 52

fAge2 = DateDiff("yyyy", DOB, dteEnd) + (DateSerial(Year(dteEnd), Month(DOB), Day(DOB)) > dteEnd)

End Function

HTH - Bob