假设用户指定了这两个日期....
开课日期:2010-12-05
结束日期:2011-01-15
如果我选择2010年12月,我应该得到以下内容
startdate = 2010-12-05
enddate = 2010-12-31
选择2011年1月然后
startdate = 2011-01-01
enddate = 2011-01-15
我应该减去日期吗?我怎样才能获得开始和结束日期 基于总体开始和结束日期的当前月/年。我在vb.net编码
答案 0 :(得分:1)
如果我的心灵感应仍然有效,那可能是:
Dim startDate As Date = DateTimePicker1.Value
Dim endDate As Date = DateTimePicker2.Value
Dim selectedDate As Date = New DateTime(DateTimePicker3.Value.Year, DateTimePicker3.Value.Month, 1)
If selectedDate >= startDate AndAlso selectedDate <= endDate Then
Dim resultStartDate = New DateTime(Math.Max(startDate.Ticks, selectedDate.Ticks))
Dim resultEndDate = New DateTime(Math.Min(endDate.Ticks, selectedDate.AddMonths(1).AddDays(-1).Ticks))
Else
MsgBox("Outside of range")
End If