<jo*****@zeus.kern.org> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
Hello-
I've looked at all the age calulation solutions - but I'm a little
stumped on how to set this one up. Here is what I need to do.
I need to find all the kids in my DB that are currently 11 or 12 years
of age
AND
All the kids who WILL BE 11 on or before Dec 31, 2005.
The current kids aren't an issue - but how do I calculate who is 10 now
and will have a birthday between tomorrow and 12/31/05 ???
Appreciate any suggestions,
john-
To find the kids who are 10 now but will be 11 by the end of the year is
easy enough, but do you realise that some of the kids who are currently 11
or 12 may no longer be 11 or 12 by the end of the year?
Imagine you write a function which takes the kid's date of birth and the
'EventDate' (could be today or a date in the future) and it returns the
number of years old. If you want to generalise the function so it handles:
How old will the person be at the end of this year? How old was the person 5
years ago? you will need to think about negative numbers. My function
ignores dates in the past and simply returns zero.
If there is a field for date of birth called [DOB] you could write:
AgeNow:AgeOnDate(Date(),[DOB])
AgeAtYearEnd:AgeOnDate(DateSerial(Year(Date(),12,3 1),[DOB])
Public Function AgeOnDate(dteDate As Date, dteBirthDate As Date) As Long
If dteDate > dteBirthDate Then
AgeOnDate = DateDiff("yyyy", dteBirthDate, dteDate) - _
IIf(Format(dteDate, "mmdd") < _
Format(dteBirthDate, "mmdd"), 1, 0)
End If
End Function