SET DATEFIRST (T-SQL)

Sets the first day of the week to a number from 1 through 7.

Syntax

SET DATEFIRST {number | @number_var}

Arguments
number | @number_var
Is the an integer indicating the first day of the week, and can be one of these values.

 

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

Remarks

Use the @@DATEFIRST function to check the current setting of SET DATEFIRST.

The setting of SET DATEFIRST is set at execute or run time and not at parse time.

Permissions

SET DATEFIRST permissions default to all users.

Examples

This example displays the day of the week for a date value and shows the effects of changing the DATEFIRST setting.

-- 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

  

See Also
@@DATEFIRST datetime and smalldatetime
Data Types SET

  


(c) 1988-98 Microsoft Corporation. All Rights Reserved.