declare @CurrentWeek date, @CurrentMonth date, @Year date, @LastWeek date, @LastMonth date, @LastYear date
Declare @DateValue DateTime = '3/24/2011'
select @CurrentWeek = DATEADD (wk, datediff( wk, 6, @DateValue ), 6 )
select @LastWeek = DATEADD(Wk, -1, (@CurrentWeek))
select @CurrentMonth = CONVERT(date, CONVERT(varchar, DatePart (M, @DateValue)) + '/1/' + convert(varchar, DATEPART(YEAR,@DateValue)))
select @LastMonth = CONVERT(date, DATEADD(M,-1 , @CurrentMonth), 106)
select @Year = CONVERT(date, CONVERT(varchar, '1/1/' + convert(varchar,DATEPART(YEAR,@DateValue))))
select @LastYear = CONVERT(date,DATEADD(YEAR, -1,@Year),106)
select @CurrentWeek,@LastWeek,@CurrentMonth,@LastMonth, @Year, @LastYear
No comments:
Post a Comment