SQL 中的 @@DATEFIRST

SQL Server 中的 @@DATEFIRST 是 日期和时间函数之一,它将返回一周的第一天。此值介于 1 和 7 之间。如果您的默认语言是美式英语,则默认返回 7。

SQL Server @@DATEFIRST 的基本语法是

@@DATEFIRST

SQL @@DATEFIRST 示例

在此 日期和时间函数 示例中,我们将展示如何使用 @@DATEFIRST。为了更好地理解这一点,我们使用 SQL Server 中的 SET DATEFIRST 函数来更改一周的第一天。

-- It will Return the Default first Day
SELECT @@DATEFIRST AS 'First day of the Week'

-- Set the DateFirst Value to 2 (Tuesday)
SET DATEFIRST 2;

-- Now let me select the first Day Value
SELECT @@DATEFIRST AS 'First day of the Week'

SELECT GETDATE() AS 'Today', 
       DATEPART(dw, GETDATE()) AS 'Today Number'
@@DATEFIRST in SQL Server