首页 > 代码库 > 根据日期类型字段获取年、季度、周(SQLSERVER)

根据日期类型字段获取年、季度、周(SQLSERVER)

SELECT     YEAR(CollectionDate) AS Year, DATEDIFF(quarter, CAST(DATEPART(YEAR, CollectionDate) AS NVARCHAR(4)) + ‘-01-01‘, CollectionDate) + 1 AS Quarter, DATEDIFF(week,CAST(DATEPART(YEAR, CollectionDate) AS NVARCHAR(4)) + ‘-01-01‘, CollectionDate) - DATEDIFF(quarter, CAST(DATEPART(YEAR, CollectionDate) AS NVARCHAR(4)) + ‘-01-01‘, CollectionDate) * 13 + 1 AS Week, CollectionDate
FROM         dbo.CollectionInformationList