SET DATEFORMAT (Transact-SQL)
SQL Server 2005
Sets the order of the dateparts (month/day/year) for entering datetime or smalldatetime data.
Transact-SQL Syntax Conventions
This setting is used only in the interpretation of character strings as they are converted to date values. It does not affect the display of date values.
The setting of SET DATEFORMAT is set at execute or run time and not at parse time.
SET DATEFORMAT overrides the implicit date format setting of SET LANGUAGE.
The following example uses different date formats to handle date strings in different formats.
-- Set date format to month, day, year. SET DATEFORMAT mdy; GO DECLARE @datevar DATETIME; SET @datevar = '12/31/1998'; SELECT @datevar AS DateVar; GO -- Result: 1998-12-31 00:00:00.000 -- Set date format to year, day, month. SET DATEFORMAT ydm; GO DECLARE @datevar DATETIME; SET @datevar = '1998/31/12'; SELECT @datevar AS DateVar; GO -- Result: 1998-12-31 00:00:00.000 -- Set date format to year, month, day. SET DATEFORMAT ymd; GO DECLARE @datevar DATETIME; SET @datevar = '1998/12/31'; SELECT @datevar AS DateVar; GO -- Result: 1998-12-31 00:00:00.000
Reference
CREATE FUNCTION (Transact-SQL)Data Types (Transact-SQL)
Date and Time (Transact-SQL)
SET (Transact-SQL)