Option Compare Database
Option Explicit
Function chgmonth(yourdate As Date)
Dim thisdate As Date
thisdate = date
If (Format(thisdate, "mm") < Format(yourdate, "mm")) Then
If (Format(thisdate, "dd") > Format(yourdate, "dd")) Then
chgmonth = 12 + Format(thisdate, "mm") - Format(yourdate, "mm")
Else
chgmonth = 12 + Format(thisdate, "mm") - Format(yourdate, "mm") - 1
End If
Else
If (Format(thisdate, "dd") > Format(yourdate, "dd")) Then
chgmonth = Format(thisdate, "mm") - Format(yourdate, "mm")
Else
If (Format(thisdate, "mm") = Format(yourdate, "mm")) Then
chgmonth = 11
Else
chgmonth = Format(thisdate, "mm") - Format(yourdate, "mm") - 1
End If
End If
If chgmonth < 0 Then
chgmonth = 0
End If
End If
End Function
Function chgthaitoengl(getdate As String)
' get วัน/เดือน/ปี เช่น 31/12/2512
chgthaitoengl = Mid(getdate, 1, 2) & "/" & Mid(getdate, 4, 2)
chgthaitoengl = chgthaitoengl + "/" & Mid(getdate, 7, 4) - 543
chgthaitoengl = Format(chgthaitoengl, "dd/mm/yyyy")
End Function
Function chgyear(getdate As Date)
chgyear = Int(Format(date - getdate, "Fixed") / 365)
End Function
Function chgdate(getdate As Date)
chgdate = Format(date - getdate, "Fixed") Mod 365
chgdate = chgdate Mod 30
End Function
Function showdate(getdate As Date)
If chgyear(getdate) > 0 Then showdate = chgyear(getdate) & " ปี "
If chgmonth(getdate) > 0 Then showdate = showdate & chgmonth(getdate) & " เดือน "
If chgdate(getdate) > 0 Then showdate = showdate & chgdate(getdate) & " วัน "
End Function
|