[CODE]
Public Function GetAccurateAge(ByVal dtefrom As Date, _
ByVal dteto As Date) As Integer
On Error GoTo ErrHandler
Dim intFromDay As Integer, intFromMon As Integer, intFromYr As Integer
Dim intToDay As Integer, intToMon As Integer, intToYr As Integer
Dim intResultAge As Integer
intFromYr = Year(dtefrom)
intFromMon = Month(dtefrom)
intFromDay = Day(dtefrom)
intToYr = Year(dteto)
intToMon = Month(dteto)
intToDay = Day(dteto)
If intFromYr <= intToYr Then
intResultAge = intToYr - intFromYr
Else
GetAccurateAge = -1: Exit Function ' invalid value
End If
If intFromMon <= intToMon Then
If (intFromMon = intToMon) And (intFromDay > intToDay) Then
intResultAge = intResultAge - 1
Else
intResultAge = intResultAge
End If
Else
intResultAge = intResultAge - 1
End If
GetAccurateAge = intResultAge
GetAccurateAgeExit:
Exit Function
ErrHandler:
GetAccurateAge = -1
End Function
[/CODE]