Skip to content

Latest commit

 

History

History
105 lines (86 loc) · 3.61 KB

File metadata and controls

105 lines (86 loc) · 3.61 KB

title: "@@DATEFIRST (Transact-SQL) | Microsoft Docs" ms.custom: "" ms.date: "09/18/2017" ms.prod: "sql" ms.prod_service: "database-engine, sql-database, sql-data-warehouse, pdw" ms.service: "" ms.component: "t-sql|functions" ms.reviewer: "" ms.suite: "sql" ms.technology:

  • "database-engine" ms.tgt_pltfrm: "" ms.topic: "language-reference" f1_keywords:
  • "DATE_FORMAT_TSQL"
  • "DATE FORMAT"
  • "@@DATEFIRST_TSQL"
  • "@@DATEFIRST" dev_langs:
  • "TSQL" helpviewer_keywords:
  • "dates [SQL Server], functions"
  • "date and time [SQL Server], SET DATEFIRST"
  • "first day of week [SQL Server]"
  • "dates [SQL Server], first day of week"
  • "day of week [SQL Server]"
  • "SET DATEFIRST option [SQL Server]"
  • "date and time [SQL Server], DATEFIRST"
  • "DATEFIRST option [SQL Server]"
  • "date and time [SQL Server], @@DATEFIRST"
  • "weekdays [SQL Server]"
  • "@@DATEFIRST function [SQL Server]"
  • "functions [SQL Server], date and time"
  • "options [SQL Server], date" ms.assetid: a178868e-49d5-4bd5-a5e2-1283409c8ce6 caps.latest.revision: 46 author: "edmacauley" ms.author: "edmaca" manager: "craigg" ms.workload: "On Demand" monikerRange: ">= aps-pdw-2016 || = azuresqldb-current || = azure-sqldw-latest || >= sql-server-2016 || = sqlallproducts-allversions"

@@DATEFIRST (Transact-SQL)

[!INCLUDEtsql-appliesto-ss2008-all-md]

Returns the current value, for a session, of SET DATEFIRST.

For an overview of all [!INCLUDEtsql] date and time data types and functions, see Date and Time Data Types and Functions (Transact-SQL).

Topic link icon Transact-SQL Syntax Conventions

Syntax

@@DATEFIRST  

Return Type

tinyint

Remarks

SET DATEFIRST specifies the first day of the week. The U.S. English default is 7, Sunday.

This language setting affects the interpretation of character strings as they are converted to date values for storage in the database, and the display of date values that are stored in the database. This setting does not affect the storage format of date data. In the following example, the language is first set to Italian. The statement SELECT @@DATEFIRST; returns 1. The language is then set to us_english. The statement SELECT @@DATEFIRST; returns 7.

SET LANGUAGE Italian;  
GO  
SELECT @@DATEFIRST;  
GO  
SET LANGUAGE us_english;  
GO  
SELECT @@DATEFIRST;  

Examples

The following example sets the first day of the week to 5 (Friday), and assumes the current day, Today, to be 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';  

[!INCLUDEssResult]

First Day         Today  
----------------  --------------  
5                 2  

Example

[!INCLUDEssSDWfull] and [!INCLUDEssPDW]

SELECT @@DATEFIRST;  

See also

Configuration Functions (Transact-SQL)