Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim DateBirth As Date = date_birthday.Text
Dim DateCalc As Date = date_now.Text
Dim DateTemp As Date
Dim d, m, y As Integer
If DateBirth > DateCalc Then
MessageBox.Show("", "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End If
'//-- คำนวณหาปี
y = DateCalc.Year - DateBirth.Year
DateTemp = DateAdd(DateInterval.Year, y, DateBirth)
y = y + (DateTemp > DateCalc)
'//-- คำนวณหาเดือน
DateBirth = DateAdd(DateInterval.Year, y, DateBirth)
m = DateDiff(DateInterval.Month, DateBirth, DateCalc)
m = m + (DateAdd(DateInterval.Month, m, DateBirth) > DateCalc)
'//-- คำนวณหาวัน
DateBirth = DateAdd(DateInterval.Month, m, DateBirth)
d = DateDiff(DateInterval.Day, DateBirth, DateCalc)
d = d + (DateAdd(DateInterval.Day, d, DateBirth) > DateCalc)
TextBox1.Text = "อายุตอนนี้ : " & y & " ปี " & m & " เดือน " & d & " วัน "
Dim d4 As Date = CDate(date_birthday.Text)
d4 = d4.AddYears(60)
date_retire.Text = CStr(d4)
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", date_now.Text, date_retire.Text)
Date3 = DateAdd("yyyy", Year1, date_now.Text)
If Date3 > date_retire.Text Then
Date3 = DateAdd("yyyy", -1, Date3)
Year1 = Year1 - 1
End If
Month1 = DateDiff("m", Date3, date_retire.Text)
Date3 = DateAdd("m", Month1, Date3)
If Date3 > date_retire.Text Then
Date3 = DateAdd("m", -1, Date3)
Month1 = Month1 - 1
End If
Day1 = DateDiff("d", Date3, date_retire.Text)
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
TextBox2.Text = "เหลืออีก : " & dDay1 & dMonth1 & dYear1
End Sub