Is there a built in function to convert Date of Birth to age? I've written one myself but it's not particularly swift.
Public Function DateToAge(DOB As Date) As Integer
Dim dOBM, dOBD, todayM, todayD, age As Integer
dOBM = DatePart("m", DOB)
dOBD = DatePart("d", DOB)
todayM = DatePart("m", Date)
todayD = DatePart("d", Date)
age = (DateDiff("yyyy", DOB, Date)) - 1
If dOBM <= todayD Then
If dOBD <= todayD Then
age = DateDiff("yyyy", DOB, Date)
End If
End If
DateToAge = age
End Function
If there isn't a built in function can anyone improve on mine?
Thanks in Advance
Pete
Public Function DateToAge(DOB As Date) As Integer
Dim dOBM, dOBD, todayM, todayD, age As Integer
dOBM = DatePart("m", DOB)
dOBD = DatePart("d", DOB)
todayM = DatePart("m", Date)
todayD = DatePart("d", Date)
age = (DateDiff("yyyy", DOB, Date)) - 1
If dOBM <= todayD Then
If dOBD <= todayD Then
age = DateDiff("yyyy", DOB, Date)
End If
End If
DateToAge = age
End Function
If there isn't a built in function can anyone improve on mine?
Thanks in Advance
Pete