SET DATEFORMAT 的设置是在执行或运行时设置,而不是在分析时设置。
SET DATEFORMAT 将覆盖 SET LANGUAGE 的隐式日期格式设置。
该设置仅用在将字符串转换为日期值时的解释中。它不影响日期值的显示。
SET DATEFORMAT mdy
SELECT DATEPART(yy, '12/09/10') AS 'Year Number'
------------------------------
Year Number
2010
==================
SET DATEFORMAT ymd
SELECT DATEPART(yy, '12/09/10') AS 'Year Number'
------------------------------
Year Number
2012
==================
SET DATEFIRST 1
SELECT DATEPART(dw, '12/09/10') AS 'date var'
--------------------------------------
date var
1
=====================
SET DATEFIRST 7
SELECT DATEPART(dw, '12/09/10') AS 'date var'
--------------------------------------
date var
2
=====================
SET DATEFORMAT mdy;
DECLARE @datevar DATETIME;
SET @datevar = '12/31/1998';
SELECT datepart(yy,dateadd(yy,-2,@datevar)) AS DateVar;
-----------------------------------------
DateVar
1996
======================