从日期获取年,月或日
参考:
DECLARE @D DATETIME = GETDATE() SELECT DATEPART(YEAR,@D) AS [YEAR], DATEPART(MONTH,@D) AS [MONTH], DATEPART(DAY,@D) AS [DAY] SELECT YEAR(@D) AS [YEAR], MONTH(@D) AS [MONTH], DAY(@D) AS [DAY]
参考:
DECLARE @D DATETIME = GETDATE() SELECT DATEPART(YEAR,@D) AS [YEAR], DATEPART(MONTH,@D) AS [MONTH], DATEPART(DAY,@D) AS [DAY] SELECT YEAR(@D) AS [YEAR], MONTH(@D) AS [MONTH], DAY(@D) AS [DAY]