Share via


SET DATEFIRST (Transact-SQL)

週の最初の曜日を 1 ~ 7 の数値で設定します。

トピック リンク アイコンTransact-SQL 構文表記規則

構文

SET DATEFIRST { number | @number_var } 

引数

number | **@**number_var

週の最初の曜日を示す整数値を指定します。次の値のいずれかです。

週の最初の曜日

1

月曜日

2

火曜日

3

水曜日

4

木曜日

5

金曜日

6

土曜日

7 (既定値)

日曜日

解説

SET DATEFIRST の現在の設定を確認するには、@@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 の参考資料の入手