SQL SERVER – @@DATEFIRST and SET DATEFIRST Relations and Usage

SET DATEFIRST and @@DATEFIRST control and report the first day of the week in SQL Server. The master database’s syslanguages table has a DateFirst column that defines the first day of the week for a particular language. SQL Server with US English as default language, SQL Server sets DATEFIRST to 7 (Sunday) by default. We can reset any day as first day of the week using

SQL SERVER - @@DATEFIRST and SET DATEFIRST Relations and Usage

SET DATEFIRST 5

This will set Friday as first day of week.
@@DATEFIRST returns the current value, for the session, of SET DATEFIRST.

SET LANGUAGE italian
GO
SELECT @@DATEFIRST
GO
----This will return result as 1(Monday)
SET LANGUAGE us_english
GO
SELECT @@DATEFIRST
GO
----This will return result as 7(Sunday)

In this way @@DATEFIRST and SET DATEFIRST are related. When I learned about this feature I was very glad as our company has started to server global clients and simple feature like this helps a lot to avoid confusion.

Published by Pinal Dave on SQLAuthority. More of my work at pinaldave.com.


Discover more from SQL Authority with Pinal Dave

Subscribe to get the latest posts sent to your email.

SQL DateTime, SQL Function, SQL Scripts, SQL Utility
Previous Post
SQL SERVER – Fix : Error 1418 – Microsoft SQL Server – The server network address can not be reached
Next Post
SQL SERVER – Query to Find Seed Values, Increment Values and Current Identity Column value of the table

Related Posts

4 Comments. Leave new

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.