Date Formats ( YYYY-Quarter, YYYY-MM-Week)

Bandi
Posted by Bandi under Sql Server category on | Points: 40 | Views : 417
DECLARE @date VARCHAR(10) = '20130913' --YYYYMMDD 
SELECT DATENAME(year,@date) + '-' + DATENAME(quarter,@date) AS [YYYY-quater]
,DATENAME(year,@date) + '-' + RIGHT('00' + CAST(DATEPART(month,@date) AS varchar(2)),2) + '-' + DATENAME(ISO_week,@date) AS [YYYY-MM-Week]

OUTPUT:
YYYY-quater YYYY-MM-Week
2013-3 2013-09-37

Comments or Responses

Login to post response