Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register todayThis browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Applies to:
SQL Server
Azure SQL Database
Azure SQL Managed Instance
Azure Synapse Analytics
Analytics Platform System (PDW)
SQL analytics endpoint in Microsoft Fabric
Warehouse in Microsoft Fabric
This function returns the current value of SET DATEFIRST, for a specific session.
See Date and Time Data Types and Functions (Transact-SQL) for an overview of all Transact-SQL date and time data types and functions.
Transact-SQL syntax conventions
@@DATEFIRST
tinyint
SET DATEFIRST n specifies the first day (SUNDAY, MONDAY, TUESDAY, etc.) of the week. The value of n ranges from 1 to 7.
SET DATEFIRST 3;
GO
SELECT @@DATEFIRST; -- 3 (Wednesday)
GO
For a U.S. English environment, @@DATEFIRST defaults to 7 (Sunday).
This language setting impacts character string interpretation as SQL Server converts those strings to date values for database storage. This setting also impacts display of date values stored in the database. This setting does not impact the storage format of date data.
This example first sets the language to Italian
. The statement SELECT @@DATEFIRST;
returns 1
. The next statement sets the language to is then set to us_english
. The final statement, SELECT @@DATEFIRST;
returns 7
.
SET LANGUAGE Italian;
GO
SELECT @@DATEFIRST;
GO
SET LANGUAGE us_english;
GO
SELECT @@DATEFIRST;
This example sets the first day of the week to 5
(Friday), and assumes that the current day, Today
, falls on Saturday. The SELECT
statement returns the DATEFIRST
value and the number of the current day of the week.
SET DATEFIRST 5;
SELECT @@DATEFIRST AS 'First Day'
,DATEPART(dw, SYSDATETIME()) AS 'Today';
Here's the result set.
First Day Today
---------------- --------------
5 2
Azure Synapse Analytics and Analytics Platform System (PDW)
SELECT @@DATEFIRST;
Events
Mar 31, 11 PM - Apr 2, 11 PM
The biggest SQL, Fabric and Power BI learning event. March 31 – April 2. Use code FABINSIDER to save $400.
Register today