-
Each datepart and its abbreviations return the same value.
The return value depends on the language environment set by using SET LANGUAGE and by the default language of the login. The return value is dependant on SET DATEFORMAT if date is a string literal of some formats. SET DATEFORMAT does not affect the return value when the date is a column expression of a date or time data type.
For versions of SQL Server later than SQL Server 2000, when the date parameter has a date data type argument, the return value depends on the setting specified by using SET DATEFIRST.
TZoffset datepart Argument
If datepart argument is TZoffset (tz) and the date argument has no time zone offset, 0 is returned.
smalldatetime date Argument
Default Returned for a datepart That Is Not in the date Argument
If the data type of the date argument does not have the specified datepart, the default for that datepart will be returned.
For example, the default year-month-day for any date data type is 1900-01-01. The following statement has date part arguments for datepart, a time argument for date, and returns 1900, January, 1, 1, Monday.
SELECT DATENAME(year, '12:10:30.123')
,DATENAME(month, '12:10:30.123')
,DATENAME(day, '12:10:30.123')
,DATENAME(dayofyear, '12:10:30.123')
,DATENAME(weekday, '12:10:30.123');
The default hour-minute-second for the time data type is 00:00:00. The following statement has time part arguments for datepart, a date argument for date, and returns 0, 0, 0.
SELECT DATENAME(hour, '2007-06-01')
,DATENAME(minute, '2007-06-01')
,DATENAME(second, '2007-06-01');