Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
Public Function basDOB2AgeExt(DOB As Date, Optional AsOf As Date = -1) As String
'Michael Red 5/23/02
'Dob is just the date of Birth
'AsOf is an optional date to check - as in examples 1 & 2
'Otherwise, the DOB is checked against the Current Date
'? basDOB2AgeExt(#8/21/42#)
'59 Years 9 Months and 2 Days.
'? basDOB2AgeExt(#8/21/1942#, #8/20/2022#)
'79 Years 11 Months and 30 Days.
'? basDOB2AgeExt(#8/21/1942#, #8/21/2022#)
'80 Years 0 Months and 0 Days.
Dim tmpAge As Integer 'Simple DateDiff w/o Birthday correction
Dim tmpDt As Date 'Date to use in intermediate Calcs
Dim DtCorr As Boolean 'BirthDay Before or After date in question
Dim YrsAge As Integer
Dim MnthsAge As Integer 'Additional Mnths
Dim DaysAge As Integer 'Additional Days
If (AsOf = -1) Then 'Check for (Optional Date to Check against)
AsOf = Date 'If Not Supplied, Assume Today
End If
tmpAge = DateDiff("YYYY", DOB, AsOf) 'Just the Years considering Jan 1, Mam
DtCorr = DateSerial(Year(AsOf), Month(DOB), Day(DOB)) > AsOf
YrsAge = tmpAge + DtCorr 'Just Years and Correction
tmpDt = DateAdd("yyyy", YrsAge, DOB)
MnthsAge = DateDiff("m", tmpDt, AsOf)
DtCorr = DateAdd("m", MnthsAge, tmpDt) > AsOf
MnthsAge = MnthsAge + DtCorr
tmpDt = DateAdd("m", MnthsAge, tmpDt)
DaysAge = DateDiff("d", tmpDt, AsOf)
basDOB2AgeExt = YrsAge & " Years " & MnthsAge & " Months and " & DaysAge & " Days."
End Function
[code]
MichaelRed
m.red@att.net
There is never time to do it right but there is always time to do it over