DATENAME (Transact-SQL)

Returns a character string representing the specified datepart of the specified date.

Syntax

DATENAME ( datepart , date )

Parameters

Return Type

VARCHAR

Returns a character string representing the specified datepart of the specified date.

Description

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'.

Examples

Example 1: Getting the month name

SELECT DATENAME(month, '2023-10-26');
-- Returns: October

Example 2: Getting the day of the week name

SELECT DATENAME(weekday, '2023-10-26');
-- Returns: Thursday

Example 3: Using DATENAME with a table column

Suppose you have a table named Orders with a column OrderDate of type DATE.

SELECT OrderID, DATENAME(year, OrderDate) AS OrderYear
FROM Orders;

Note

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.

Tip

DATENAME is often used for reporting and display purposes where the full name of a date part is more readable than its numerical representation.

Supported dateparts

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

Related Functions