我要求无论开始和日期是否需要循环遍历该时间跨度并计算月份级别的数字。我似乎无法弄清楚,也许这是不可能的,但我想做的事情如下:
FOREACH Month As TimeSpan in ContractRange.Months
Do Calculations (Month.Start, Month.End)
NEXT
这是可能的还是我需要计算月数,只是迭代月数并根据我的指数计算该月的开始/结束?
答案 0 :(得分:1)
Get the number of months between start and end of contract range
For each month in that list
determine start and end of that month
Do your calculations(start, end)
next month
答案 1 :(得分:0)
我会做这样的事情:
Dim CurrentDate, StartDate, EndDate as DateTime
' Get dates for contract range
GetDatesForContractRange(StartDate, EndDate) ' ref? i'm not a Vb guy
CurrentDate = StartDate
While CurrentDate < EndDate
' Calculate month bounds
Dim StartMonth, EndMonth as DateTime
StartOfMonth = CurrentDate.AddDays(-CurrentDate.Day + 1)
EndOfMonth = StartOfMonth.AddMonths(1).AddDays(-1) ' or AddSeconds(-1)
Do Calculations (StartOfMonth, EndOfMonth)
CurrentDate = CurrentDate.AddMonths(1)
End While