[AccessD] Age calculation function

Mark Whittinghill mwhittinghill at symphonyinfo.com
Thu Jul 31 15:48:02 CDT 2003


Yes, I got a bit further into it, and realized I needed a second parameter,
as won't be using it for today only.  In my version, I pass Date or the
Enddate, and make the second parameter a date type, but it's the same thing.

Mark Whittinghill
Symphony Information Services
612-333-1311
mwhittinghill at symphonyinfo.com
----- Original Message ----- 
From: "Heenan, Lambert" <Lambert.Heenan at AIG.com>
To: "'Access Developers discussion and problem solving'"
<accessd at databaseadvisors.com>
Sent: Thursday, July 31, 2003 3:34 PM
Subject: RE: [AccessD] Age calculation function


> Here's another solution...
>
> Public Function CalculateAge(datBirth As Date, Optional endDate As
Variant)
> As Long
>
>     Dim lngNumDays As Long
>     Dim eDate As Date
>     If IsMissing(endDate) Then
>         eDate = Date
>     Else
>         eDate = endDate
>     End If
>     lngNumDays = DateDiff("d", datBirth, eDate)
>     If Day(datBirth) = Day(eDate) And Month(datBirth) = Month(eDate) Then
>         ' it's the actual birthday
>         ' add 1 to compensate for .25 in the division
>         lngNumDays = lngNumDays + 1
>     End If
>     CalculateAge = Int(lngNumDays / 365.25)
> End Function
>
> Note the second variant (date) parameter. That allows you to calculate the
> age on any specific date, not just 'today'.
>
> Lambert
>




More information about the AccessD mailing list