1
지난 주 및 2 주 전에 일요일부터 토요일까지 의 기간을 가져 오려고합니다. 오늘 오늘 날짜는 10/24/2012이며, 날짜 범위는 10/21/2012입니다. - 10/27/2012T-SQL에서 datepart를 LINQ로 변환
2012 년 10 월 14 일 - 10/20/2012
지난 주 날짜 범위도 다음과 같습니다 : 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]
T 그의 결과는
[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