SET DATEFIRST (Transact-SQL)

Establece el primer día de la semana en un número del 1 al 7.

Icono de vínculo a temasConvenciones de sintaxis de Transact-SQL (Transact-SQL)

Sintaxis

SET DATEFIRST { number | @number_var } 

Argumentos

number | **@**number_var

Es un entero que indica el primer día de la semana. Puede ser uno de los siguientes valores.

Valor Primer día de la semana:

1

Lunes

2

Martes

3

Miércoles

4

Jueves

5

Viernes

6

Sábado

7 (predeterminado, inglés de EE.UU.)

Domingo

Notas

Puede utilizar la función @@DATEFIRST para ver el valor actual de SET DATEFIRST.

La opción SET DATEFIRST se establece en tiempo de ejecución, no en tiempo de análisis.

Permisos

Debe pertenecer a la función public.

Ejemplos

En el ejemplo siguiente se muestra el día de la semana correspondiente a un valor de fecha y se muestra el efecto de cambiar el valor de 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

Vea también

Referencia

Tipos de datos (Transact-SQL)
@@DATEFIRST (Transact-SQL)
Date y Time (Transact-SQL)
SET (Transact-SQL)

Ayuda e información

Obtener ayuda sobre SQL Server 2005