2011-01-12 55 views
0

假定用戶指定了這兩個日期之間的日期計算....
開始日期:2010-12-05
結束日期:2011-01-15基於兩個日期

如果我選擇2010年12月我應該得到的folllowing
開始日期= 2010-12-05
結束日期= 2010-12-31

選擇2011年1月則
開始日期= 2011-01-01
結束日期= 2011-01-15

我應該減去日期嗎?根據總的開始日期和結束日期,我如何獲得當前月份/年份的開始和結束日期:
。我編碼在vb.net

+0

你需要更具體。你實際上沒有提出一個問題,如果沒有做出一些大的假設,那麼這個問題是可以回答的。 – Darbio 2011-01-12 02:15:12

回答

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