Returns the specified datepart (the first argument) of the specified date or time (the second argument) as a character string. Takes a date, time, bigdatetime, bigtime, datetime, or smalldatetime value as its second argument.
datename(datepart {date | time | bigtime | datetime | bigdatetime})
is a date part or abbreviation. For a list of the date parts and abbreviations recognized by Adaptive Server, see “Date parts”.
is an expression of type datetime, smalldatetime, bigdatetime, bigtime, time or a character string in a datetime format.
Finds the month name of a bigdatetime:
declare @a bigdatetime select @a = "apr 12, 0001 00:00:00.010101" select datename(mm, @a) ------------------------------ April
Assumes a current date of November 20, 2000:
select datename(month, getdate())
November
Finds the month name of a date:
declare @a date select @a = "apr 12, 0001" select datename(mm, @a) ------------------------------ April
Finds the seconds of a time:
declare @a time select @a = "20:43:22" select datename(ss, @a) ------------------------------ 22
datename, a date function, returns the name of the specified part (such as the month “June”) of a datetime or smalldatetime value, as a character string. If the result is numeric, such as “23” for the day, it is still returned as a character string.
For more information about date functions, see “Date functions”.
The date part weekday or dw returns the day of the week (Sunday, Monday, and so on) when used with datename.
Since smalldatetime is accurate only to the minute, when a smalldatetime value is used with datename, seconds and milliseconds are always 0.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute datename.
Datatypes Date and time datatypes
Commands select, where clause