Tuesday, April 08, 2008

How To Get Age in Years Days and Months - Function

i ve found this code before and when i need this code again im missing it..i've spend half day to find this code and read all nonsense code...here the code snippet damn waste my time !!! sakk

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:

Locations of visitors to this page
DROP ME A MSG :D