我正在尝试获取上周和 2 周前从周日到周六的日期范围,所以今天是 10/24/2012,日期范围是:10/21/2012 - 10/27/2012
我正在尝试获取上周的日期范围,即:10/14/2012 - 10/20/2012
还有两周前的日期范围:10/07/2012 - 10/13/2012
我有正确的 SQL 查询,即
DECLARE @TodayDayOfWeek INT
DECLARE @EndOfPrevWeek DateTime
DECLARE @StartOfPrevWeek DateTime
DECLARE @EndOf2WeeksAgo DateTime
DECLARE @Start2WeeksAgo DateTime
SET @TodayDayOfWeek = datepart(dw, GetDate())
--get the last day of the previous week (last Sunday)
SET @EndOfPrevWeek = DATEADD(dd, -@TodayDayOfWeek, GetDate())
--get the first day of the previous week (the Monday before last)
SET @StartOfPrevWeek = DATEADD(dd, -(@TodayDayOfWeek+6), GetDate())
SET @EndOf2WeeksAgo = DATEADD(dd, -(@TodayDayOfWeek+7), GetDate())
SET @Start2WeeksAgo = DATEADD(dd, -(@TodayDayOfWeek+13), GetDate())
Select @StartOfPrevWeek as [Last week start date], @EndOfPrevWeek as [Last Week start date],
@Start2WeeksAgo as [2 Weeks Ago Start], @EndOf2WeeksAgo as [2 Weeks Ago End]
这导致
[Last week start date] [Last week start date] [2 Weeks Ago Start] [2 Weeks Ago End]
10/14/2012 10/20/2012 10/07/2012 10/13/2012
我如何将其转换为 Linq?我有一个日期列,需要显示这两个日期范围之间的日期,例如
last week date 2 weeks ago
10/15/2012 10/08/2012
10/18/2012 10/11/2012