with my code below I'm able to select row .field ("Objectif) values based on current week and current year from datatable(dt1). how can I do the same by putting a range of date as condition ? example from Sept 01 2014 to Sept 01 2015 .thanks
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")
)
Well you can use <
and >
with DateTime
values, so you can do something like:
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
That's treating lowerBound
as inclusive and upperBound
as exclusive, which is usually (but not always) a good idea.
See more on this question at Stackoverflow