Returns a character string representing the specified datepart of the specified date.
DATENAME ( datepart , date )
datepart
: The part of the date that will be returned. This parameter can be any valid integer value for the datepart argument in the DATEPART
function.date
: The expression that evaluates to a valid date, date/time, or datetime2 value.Returns a character string representing the specified datepart of the specified date.
DATENAME
returns a character string that represents the specified datepart
of the specified date
.
The return value corresponds to the name of the specified datepart. For example, if datepart
is month
and date
is '2023-10-26'
, DATENAME
returns 'October'.
SELECT DATENAME(month, '2023-10-26');
-- Returns: October
SELECT DATENAME(weekday, '2023-10-26');
-- Returns: Thursday
Suppose you have a table named Orders
with a column OrderDate
of type DATE
.
SELECT OrderID, DATENAME(year, OrderDate) AS OrderYear
FROM Orders;
The language of the return value is determined by the language setting of the current session. You can change the language by using the SET LANGUAGE
statement.
DATENAME
is often used for reporting and display purposes where the full name of a date part is more readable than its numerical representation.
The following table lists the supported dateparts for the DATENAME
function:
Datepart | Abbreviation |
---|---|
year | yy, yyyy |
quarter | qq, q |
month | mm, m |
dayofyear | dy, y |
day | dd, d |
week | wk, ww |
weekday | dw, w |
hour | hh |
minute | mi, n |
second | ss, s |
millisecond | ms |
microsecond | mcs |
nanosecond | ncs |