Declare @InputDate datetime
Set @InputDate = '2008-09-22'
Select Case when Datepart(Q,@InputDate) = 1 then 'Q1'
when Datepart(Q,@InputDate) = 2 then 'Q2'
when Datepart(Q,@InputDate) = 3 then 'Q3'
when Datepart(Q,@InputDate) = 4 then 'Q4'
end as Quarter
,CAST(YEAR(@InputDate) AS VARCHAR(4)) +
CASE WHEN MONTH(@InputDate) IN ( 1, 2, 3) THEN '/01/01'
WHEN MONTH(@InputDate) IN ( 4, 5, 6) THEN '/04/01'
WHEN MONTH(@InputDate) IN ( 7, 8, 9) THEN '/07/01'
WHEN MONTH(@InputDate) IN (10, 11, 12) THEN '/10/01'
END
as QuarterStartDate
,CAST(YEAR(@InputDate) AS VARCHAR(4)) +
CASE WHEN MONTH(@InputDate) IN ( 1, 2, 3) THEN '/03/31'
WHEN MONTH(@InputDate) IN ( 4, 5, 6) THEN '/06/30'
WHEN MONTH(@InputDate) IN ( 7, 8, 9) THEN '/09/30'
WHEN MONTH(@InputDate) IN (10, 11, 12) THEN '/12/31'
END
as QuarterEndDate
,dateadd( month, datediff( month, 0, @InputDate ), 0 ) as BeginMonth
,Cast(convert(varchar(10),@InputDate,120)as datetime)-
datepart(dw, cast(convert(varchar(10),@InputDate,120)as datetime))+1 as StartofWeek
,Cast(convert(varchar(10),@InputDate,120)as datetime)-
datepart(dw, cast(convert(varchar(10),@InputDate,120)as datetime))+7 as EndofWeek
|