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 basDOB2Age(Dob As Date, Optional AsOf As Date = -1) As Integer
'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
'Michael Red 12/15/2001
'To Calculate Age from Date of Birth
'Sample Useage:
'? basDOB2Age(#8/21/1942#, #8/21/2022#)
'80
'? basDOB2Age(#8/21/1942#, #8/20/2022#)
'79
'? basDOB2Age(#8/21/1942#)
'59
Dim tmpAge As Integer 'Simple DateDiff w/o Birthday correction
Dim BrthDayCorr As Boolean 'BirthDay Before or After date in question
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
BrthDayCorr = DateSerial(Year(AsOf), Month(Dob), Day(Dob)) > AsOf 'Check This Year
basDOB2Age = tmpAge + BrthDayCorr 'Just Years and Correction
End Function