Using SQL Server 2005:
How can I get the numerical day of the month and day of the quarter in a query?
DECLARE @DATE DATETIME SET @DATE = GETDATE() SELECT DATEPART(dy, @DATE) AS DayOfYear --, <something> AS DayOfQuarter --, <something> AS DayOfMonth , DATEPART(dw, @DATE) AS DayOfWeek
Thanks in advance!
Advertisement
Answer
DECLARE @DATE DATETIME SET @DATE = GETDATE() SELECT DATEPART(dy, @DATE) AS DayOfYear , DATEDIFF(d, DATEADD(qq, DATEDIFF(qq, 0, @DATE), 0), @DATE) + 1 AS DayOfQuarter , DAY(@Date) AS DayOfMonth , DATEPART(dw, @DATE) AS DayOfWeek