5
Cómo escribo la declaración where
que selecciona registros con el campo Date
entre Sunday
a Saturday
de una fecha determinada.Seleccione la semana actual usando LINQ
Data Fields: Id, Name, Date
Cómo escribo la declaración where
que selecciona registros con el campo Date
entre Sunday
a Saturday
de una fecha determinada.Seleccione la semana actual usando LINQ
Data Fields: Id, Name, Date
Dónde date
es la fecha en cuestión, ¿qué tal:
DateTime start = date.Date.AddDays(-(int)date.DayOfWeek), // prev sunday 00:00
end = start.AddDays(7); // next sunday 00:00
var qry = from record in data
where record.Date >= start // include start
&& record.Date < end // exclude end
select record;
DateTime givenDate = DateTime.Today;
DateTime startOfWeek = givenDate.AddDays(-1 * givenDate.DayOfWeek);
DateTime endOfWeek = startOfWeek.AddDays(7);
var query = myObjects
.Where(ob => startOfWeek <= ob.DateField && ob.DateField < endOfWeek)