patternsqlMinor
Does the week day number changes according to localization in SQL Server?
Viewed 0 times
numberthesqllocalizationweekchangesdoesserveraccordingday
Problem
Does the weekday number changes according to server/database regional configuration in SQL Server (2005+)?
Solution
The weekday number is controlled by the
http://msdn.microsoft.com/en-us/library/ms181598.aspx
This setting is changed when the
Returns
And
Returns
You can find the
http://msdn.microsoft.com/en-us/library/ms190303.aspx
SET DATEFIRST setting.http://msdn.microsoft.com/en-us/library/ms181598.aspx
This setting is changed when the
SET LANGUAGE setting is changed. SET LANGUAGE English;
GO
SELECT
@@DATEFIRST as DateFirst,
CAST('1999-1-1' AS datetime2) AS SelectDate,
DATEPART(dw, '1999-1-1') AS DayOfWeek;Returns
DATEFIRST SELECTDATE DAYOFWEEK
7 1999-01-01 00:00:00.0000000 6And
SET LANGUAGE German;
GO
SELECT
@@DATEFIRST as DateFist,
CAST('1999-1-1' AS datetime2) AS SelectDate,
DATEPART(dw, '1999-1-1') AS DayOfWeek;Returns
DATEFIRST SELECTDATE DAYOFWEEK
1 1999-01-01 00:00:00.0000000 5You can find the
DATEFIRST setting for each language by querying sys.syslanguages view and referencing the datefist column.http://msdn.microsoft.com/en-us/library/ms190303.aspx
Code Snippets
SET LANGUAGE English;
GO
SELECT
@@DATEFIRST as DateFirst,
CAST('1999-1-1' AS datetime2) AS SelectDate,
DATEPART(dw, '1999-1-1') AS DayOfWeek;DATEFIRST SELECTDATE DAYOFWEEK
7 1999-01-01 00:00:00.0000000 6SET LANGUAGE German;
GO
SELECT
@@DATEFIRST as DateFist,
CAST('1999-1-1' AS datetime2) AS SelectDate,
DATEPART(dw, '1999-1-1') AS DayOfWeek;DATEFIRST SELECTDATE DAYOFWEEK
1 1999-01-01 00:00:00.0000000 5Context
StackExchange Database Administrators Q#44328, answer score: 4
Revisions (0)
No revisions yet.