David Fenton
dfe at nudgeeinternational.com
Sun Aug 10 18:26:15 CDT 2003
Try this simple one folks.
Actually calculates to the nearest month.
Gustav I'm not sure if it accounts for those people born on Feb 29th.
Public Function CalculateAge(datBirth As Date) As Long
'Calculates a person's age in years and months from their birthdate to today's date.
'I'm using the # marks because in Australia we format the dates differently and it doesn't seem
'to work here without them - 'cause I've tried.
'Usage for a birthdate of 1st Dec 1960 - try Debug.Print CalculateAge(#1/12/60#)
Dim lngNumDays As Long
Dim lngNumMonths As Long
Dim Months As Double
lngNumDays = DateDiff("d", Format(datBirth, "dd/mmm/yyyy"), Date)
lngNumMonths = DateDiff("m", Format(datBirth, "dd/mmm/yyyy"), Date)
CalculateAge = Int(lngNumMonths / 12)
Months = (lngNumMonths / 12) Mod 12
Debug.Print CalculateAge; " yrs " & Months & " months"
End Function
Cheers
David Ô¿Ô¬
Brisbane Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://databaseadvisors.com/pipermail/accessd/attachments/20030811/118f3bf7/attachment.html>