DATENAME (Transact-SQL)
Returns a character string that represents the specified datepart of the specified date. The return value is of the same data type as the date argument.
Syntax
DATENAME ( datepart , date )
Arguments
| Parameter | Description | Required |
|---|---|---|
datepart |
Specifies the part of the date that is to be returned. The following table lists all valid values for the datepart argument. |
Yes |
date |
The expression, column, variable, or literal that is evaluated to a date, time, or datetime value. | Yes |
Return Type
varchar
Remarks
DATENAME is the counter-part of DATEPART. DATENAME returns the name of the specified datepart, whereas DATEPART returns the integer value.
Note
For a list of valid datepart and their abbreviations, see Supported Date and Time Data Types and Functions.
Examples
The following example returns the name of the month for a given date.
SELECT DATENAME (month, '2017-08-10') AS MonthName;
Result:
August
The following example returns the name of the day of the week for a given date.
SELECT DATENAME (weekday, '2017-08-10') AS DayName;
Result:
Thursday
You can also use DATENAME with columns from a table.
SELECT DATENAME (year, OrderDate) AS OrderYear,
DATENAME (month, OrderDate) AS OrderMonthName
FROM Sales.SalesOrderHeader;