Public Function Age(Startdate As Date, Enddate As Date) As String
Dim Year1 As Integer
Dim Month1 As Integer
Dim Day1 As Integer
Dim Date3 As Date
Dim dYear1 As String
Dim dMonth1 As String
Dim dDay1 As String
Year1 = DateDiff("yyyy", Startdate, Enddate)
Date3 = DateAdd("yyyy", Year1, Startdate)
If Date3 > Enddate Then
Date3 = DateAdd("yyyy", -1, Date3)
Year1 = Year1 - 1
End If
Month1 = DateDiff("m", Date3, Enddate)
Date3 = DateAdd("m", Month1, Date3)
If Date3 > Enddate Then
Date3 = DateAdd("m", -1, Date3)
Month1 = Month1 - 1
End If
Day1 = DateDiff("d", Date3, Enddate)
If Year1 = 0 Then
dYear1 = ""
Else
dYear1 = Year1 & " ปี "
End If
If Month1 = 0 Then
dMonth1 = ""
Else
dMonth1 = Month1 & " เดือน "
End If
If Day1 = 0 Then
dDay1 = ""
Else
dDay1 = Day1 & " วัน"
End If