Returns the name of the specified part of a datetime value.
datename (datepart, date)
is a date part or abbreviation. For a list of the date parts and abbreviations recognized by Adaptive Server, see “Date parts”.
can be either the function getdate, a character string in an acceptable date format, an expression that evaluates to a valid date format, or the name of a datetime or smalldatetime column.
This example assumes a current date of November 20, 2000:
select datename(month, getdate())
November
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.
SQL92 – Compliance level: Transact-SQL extension.
Any user can execute datename.
Datatypes Date and time datatypes
Commands select, where clause