我想在星期几之间选择数据。 一个例子是在下列时间之间选择所有数据:
日期在数据库中标记为UTC,我想要一个可以选择时区的解决方案。
如何使用C#/ Entity Framework / MSSQL选择这些数据?
以下是我按周时间获取数据的MSSQL查询示例,但这不考虑时区
select
cast(AVG(cast(success as float)*100) as decimal(18,2)) Avg,
convert(date,time) Time
from
recordings
where
Id = @Id
and time >= @startDate
and time <= @endDate
AND (
(CAST(time AS TIME) BETWEEN @mondayStart AND @mondayEnd AND DATENAME(DW, time) = 'Monday')
OR (CAST(time AS TIME) BETWEEN @tuesdayStart and @tuesdayEnd AND DATENAME(DW, time) = 'Tuesday')
OR (CAST(time AS TIME) BETWEEN @wednesdayStart and @wednesdayEnd AND DATENAME(DW, time) = 'Wednesday')
OR (CAST(time AS TIME) BETWEEN @thursdayStart and @thursdayEnd AND DATENAME(DW, time) = 'Thursday')
OR (CAST(time AS TIME) BETWEEN @fridayStart and @fridayEnd AND DATENAME(DW, time) = 'Friday')
OR (CAST(time AS TIME) BETWEEN @saturdayStart and @saturdayEnd AND DATENAME(DW, time) = 'Saturday')
OR (CAST(time AS TIME) BETWEEN @sundayStart and @sundayEnd AND DATENAME(DW, time) = 'Sunday')
)
group by
convert(date, time)
order by
convert(date, time)
答案 0 :(得分:-1)
var result = context.YourEntityName.Where(entry => entry.DateField >= minDate && entry.DateField <= maxDate).ToList();