增加日期35天并将结果存储在数组中

时间:2016-06-14 07:17:38

标签: vb.net

虽然我知道'如何'这样做,但在我的脑海里,我想确保我正在充分利用语法来执行任务。
我希望约会,并增加35天的增量,直到它到达未来的日期 在VB.NET中有更简洁的方法吗?

'\* define the end of the repeat period (where dteValuationDate is, say, 01/01/2016)...
dteReminderEndDate = DateAdd(DateInterval.Month, 15, dteValuationDate)
'\* define the start date for the loop (which is a specific date, say, 17/05/2016, and add 70 days to it)...
dteLoopStart = DateAdd(DateInterval.Day, 70, dteStartDate)          
intDateCount = 1            
While dteRollingDate < dteReminderEndDate
   '\* calculate the actual unadjusted rolling date...
   dteRollingDate = DateAdd(DateInterval.Day, (intDateCount * 35), dteLopStart)                
   _dteReminderDates(intDateCount) = dteRollingDate              
   intDateCount = intDateCount + 1                
   ReDim Preserve _dteReminderDates(intDateCount)
End While

所以我只想存储在结束日期之前的日期,即01/01 / 2016 + 15个月。虽然我觉得我所做的基本上是“正确的”,但我很想知道是否有更好的(读取更整洁)方法来做到这一点?

1 个答案:

答案 0 :(得分:3)

我认为这实际上是你在寻找:

Dim startDate As Date = Convert.ToDateTime("01/01/2016")
Dim endDate As Date = Convert.ToDateTime("17/05/2016")
Dim PossibleDateList As List(Of Date) = New List(Of Date)
While startDate <= endDate
    PossibleDateList.Add(startDate)
    startDate = startDate.AddDays(35)
End While

最后PossibleDateList将包含所有必需的日期