如何在SQL Server中将星期一设置为星期的第一天

时间:2022-10-21 10:43:53

I am running SQL Server 2008 on a machine with regional settings that have Monday as the first day of the week. If I create a computed column in a table to compute the day of week for a date field then I get 2 for a Monday date instead of 1.

我在具有区域设置的计算机上运行SQL Server 2008,该区域设置将星期一作为一周的第一天。如果我在表中创建一个计算列来计算日期字段的星期几,那么我得到2表示星期一而不是1。

Is there some property for the table or database or server that I need to set ?

是否需要设置表或数据库或服务器的某些属性?

2 个解决方案

#1


16  

The first day of the week is based on your language settings of the server. The default setting for us_english is 7 (Sunday)

一周的第一天基于您的服务器语言设置。 us_english的默认设置是7(星期日)

You can find the current first day of the week by using SELECT @@DATEFIRST

您可以使用SELECT @@ DATEFIRST找到当前的第一天


However, you can use DATEFIRST for this. Just put it at the top of your query

但是,您可以使用DATEFIRST。只需将其放在查询的顶部即可

SET DATEFIRST 1; this sets Monday to the first day of the week for the current connection.

SET DATEFIRST 1;这将星期一设置为当前连接的一周的第一天。

http://technet.microsoft.com/en-us/library/ms181598.aspx

http://technet.microsoft.com/en-us/library/ms181598.aspx

#2


3  

Just set in query

只需设置查询

SET DATEFIRST 1;

SET DATEFIRST 1;

Value First day of the week is 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday 7 (default, U.S. English) Sunday

价值一周的第一天是1周一2周二3周三4周四5周五6周六7(默认为美国英语)周日

#1


16  

The first day of the week is based on your language settings of the server. The default setting for us_english is 7 (Sunday)

一周的第一天基于您的服务器语言设置。 us_english的默认设置是7(星期日)

You can find the current first day of the week by using SELECT @@DATEFIRST

您可以使用SELECT @@ DATEFIRST找到当前的第一天


However, you can use DATEFIRST for this. Just put it at the top of your query

但是,您可以使用DATEFIRST。只需将其放在查询的顶部即可

SET DATEFIRST 1; this sets Monday to the first day of the week for the current connection.

SET DATEFIRST 1;这将星期一设置为当前连接的一周的第一天。

http://technet.microsoft.com/en-us/library/ms181598.aspx

http://technet.microsoft.com/en-us/library/ms181598.aspx

#2


3  

Just set in query

只需设置查询

SET DATEFIRST 1;

SET DATEFIRST 1;

Value First day of the week is 1 Monday 2 Tuesday 3 Wednesday 4 Thursday 5 Friday 6 Saturday 7 (default, U.S. English) Sunday

价值一周的第一天是1周一2周二3周三4周四5周五6周六7(默认为美国英语)周日