5
Làm cách nào để viết báo cáo where
chọn bản ghi với trường Date
giữa Sunday
đến Saturday
của một ngày cụ thể.Chọn tuần hiện tại bằng cách sử dụng LINQ
Data Fields: Id, Name, Date
Làm cách nào để viết báo cáo where
chọn bản ghi với trường Date
giữa Sunday
đến Saturday
của một ngày cụ thể.Chọn tuần hiện tại bằng cách sử dụng LINQ
Data Fields: Id, Name, Date
đâu date
là ngày trong câu hỏi, làm thế nào về:
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)