开发者

Calculating Between Dates based on two dates

开发者 https://www.devze.com 2023-02-03 23:03 出处:网络
Say the user specifies these two dates.... Start 开发者_开发技巧Date: 2010-12-05 End Date:2011-01-15

Say the user specifies these two dates....

Start 开发者_开发技巧Date: 2010-12-05

End Date: 2011-01-15

If I select December 2010 I should get the folllowing

startdate = 2010-12-05

enddate = 2010-12-31

Select January 2011 then

startdate = 2011-01-01

enddate = 2011-01-15

Should I subtract dates? How can I get the start and enddate

for the current month/year based on the overall start and end date. I'm coding in vb.net


If my telepathy still works, it could be something like:

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
0

精彩评论

暂无评论...
验证码 换一张
取 消