SET DATEFIRST (Transact-SQL)

將一週的第一天設為 1-7 其中一個數字。

主題連結圖示Transact-SQL 語法慣例

語法

SET DATEFIRST { number | @number_var } 

引數

number | **@**number_var

這是一個整數,代表一週的第一天。它可以是下列值之一。

每週的第一天是

1

星期一

2

星期二

3

星期三

4

星期四

5

星期五

6

星期六

7 (預設值,U.S. English)

星期日

備註

請利用 @@DATEFIRST 函數來查看目前的 SET DATEFIRST 設定。

SET DATEFIRST 的設定是在執行階段進行設定,而不是在剖析階段進行設定。

權限

需要 public 角色中的成員資格。

範例

下列範例會顯示每週日期來作為日期值,且會顯示變更 DATEFIRST 設定的作用。

-- SET DATEFIRST to U.S. English default value of 7.
SET DATEFIRST 7;

SELECT CAST('1/1/1999' AS DATETIME) AS SelectDate, DATEPART(dw, '1/1/1999') AS DayOfWeek;
-- January 1, 1999 is a Friday. Because the U.S. English default 
-- specifies Sunday as the first day of the week, DATEPART of 1/1/1999 
-- (Friday) yields a value of 6, because Friday is the sixth day of the 
-- week when starting with Sunday as day 1.

SET DATEFIRST 3;
-- Because Wednesday is now considered the first day of the week,
-- DATEPART should now show that 1/1/1999 (a Friday) is the third day of the 
-- week. The following DATEPART function should return a value of 3.
SELECT CAST('1/1/1999' AS DATETIME) AS SelectDate, DATEPART(dw, '1/1/1999') AS DayOfWeek;
GO

請參閱

參考

資料類型 (Transact-SQL)
@@DATEFIRST (Transact-SQL)
日期和時間 (Transact-SQL)
SET (Transact-SQL)

說明及資訊

取得 SQL Server 2005 協助