將一周的第一天設(shè)置為從 1 到 7 之間的一個(gè)數(shù)字。
SET DATEFIRST { number | @number_var
}
number | @number_var
是一個(gè)整數(shù),表示一周的第一天,可以是下列值中的一個(gè)。
值 | 一周的第一天是 |
---|---|
1 | 星期一 |
2 | 星期二 |
3 | 星期三 |
4 | 星期四 |
5 | 星期五 |
6 | 星期六 |
7(默認(rèn)值,美國(guó)英語) | 星期日 |
使用 @@DATEFIRST 函數(shù)檢查 SET DATEFIRST 的當(dāng)前設(shè)置。
SET DATEFIRST 的設(shè)置是在執(zhí)行或運(yùn)行時(shí)設(shè)置,而不是在分析時(shí)設(shè)置。
SET DATEFIRST 權(quán)限默認(rèn)授予所有用戶。
下例顯示一個(gè)日期值對(duì)應(yīng)的一周中的某一天,并顯示更改 DATEFIRST 設(shè)置的效果。
-- SET DATEFIRST to U.S. English default value of 7.
SET DATEFIRST 7
GO
SELECT CAST('1/1/99' AS datetime), DATEPART(dw, '1/1/99')
-- 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/99
-- (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/99 (a Friday) is the third day of the -- week. The following DATEPART function should return a value of 3.
SELECT CAST('1/1/99' AS datetime), DATEPART(dw, '1/1/99')
GO
相關(guān)文章