In SQL Server, the first day of the week is determined by the current language settings. You can also override that with the SET DATEFIRST
statement, which allows you to explicitly set the first day of the week.
In either case, you can use the @@DATEFIRST
function to find out what settings your session is using for the first day of the week. This article demonstrates how.
Syntax
The syntax is simple. It goes like this:
@@DATEFIRST
Example
Here’s an example of usage.
SELECT @@DATEFIRST AS 'Result';
Result:
+----------+ | Result | |----------| | 7 | +----------+
This tells me that the first day of the week is Sunday. I know this because of the following table.
Mappings for the First Day of the Week
The following table shows how each value is mapped to a day of the week.
Value | First day of the week is |
---|---|
1 | Monday |
2 | Tuesday |
3 | Wednesday |
4 | Thursday |
5 | Friday |
6 | Saturday |
7 | Sunday |
So the return value of @@DATEFIRST
will be a tinyint between 1 and 7.
This value is initially determined by the current language settings, however as mentioned, you can also use SET DATEFIRST
to override the language settings.
To see what @@DATEFIRST
settings map to each language, here’s a List of All Languages and Associated Date Formats in SQL Server 2017.
You can also use the sp_helplanguage
stored procedure to return that list. To do this, see How to Find the Date Formats Used for a Specific Language in SQL Server (T-SQL).