我有一个使用 2 个日期时间选择器并在文本框中显示天数差异的子程序,我希望子程序告诉用户天数是 0 还是大于 10,允许的天数在 1 到 10 之间。然后让用户再次选择日期
Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs)Handles btnCalculate.Click
Dim dt1 As DateTime = Convert.ToDateTime(DateTimePicker1.Text)
Dim dt2 As DateTime = Convert.ToDateTime(DateTimePicker2.Text)
Dim ts As TimeSpan = dt2.Subtract(dt1)
If Convert.ToInt32(ts.Days) >= 0 Then
txtDays.Text = "Total Days are "
txtDays.AppendText(Environment.NewLine & Convert.ToInt32(ts.Days))
Else
MessageBox.Show("Invalid Input for dates (Start Date Cannot exist before End date)")
End If
End If
End Sub