1
我試圖從日期到週六獲取上週和2周前的日期範圍 因此今天是2012年10月24日,日期範圍是:2012年10月21日 - 2012年10月27日從T-SQL將datepart轉換爲LINQ
我試圖讓上週的是日期範圍: - 2012年10月14日二○一二年十月二十〇日
另外,2個星期前的是日期範圍:10/07/2012 - 2012年10月13日
我有正確的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, [email protected], 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