GetAge(<
Public Function GetAge(Date1 As Date, Date2 As Date) As String
Dim Y, M, D As Integer
Dim Temp1 As Date
Dim Age As String
Temp1 = DateSerial(Year(Date2), Month(Date1), Day(Date1))
Y = Year(Date2) - Year(Date1) + (Temp1 > Date2)
M = Month(Date2) - Month(Date1) - (12 * (Temp1 > Date2))
D = Day(Date2) - Day(Date1)
If D < 0 Then
M = M - 1
D = Day(DateSerial(Year(date2), Month(date2), 0)) + D
End If
Age = Y & " Year(s) " & M & " Month(s) and " & D & " Day(s)"
Return Age
End Function
No comments:
Post a Comment