具有日期范围的 AsEnumerable

AsEnumerable with range of dates

使用下面的代码,我可以select row .field ("Objectif) values based on current week and current year from datatable(dt1).我如何通过放置一个范围来做同样的事情日期作为条件?示例从 2014 年 9 月 1 日到 2015 年 9 月 1 日。谢谢

dim ThisWeekTotal = (
            From Row In dt1.AsEnumerable
            Where MyCalendar.GetWeekOfYear(Row.Field(Of DateTime)("date"),
                                           CalendarWeekRule.FirstFourDayWeek,
                                           DayOfWeek.Sunday) = Currentweek And MyCalendar.GetYear(Row.Field(Of DateTime)("date")) = Currentyear
            Select Row.Field(Of Double)("objectif")
        )

您可以将 <>DateTime 值一起使用,因此您可以执行以下操作:

Dim lowerBound As DateTime = ...
Dim upperBound As DateTime = ...

... in the query ...
   Where lowerBound <= Row.Field(Of DateTime)("date") AndAlso
         Row.Field(Of DateTime)("date") < upperBound

lowerBound 视为包容性的,将 upperBound 视为独占的,通常(但不总是)是个好主意。