Menu

SQL Server DATENAME() Function

Updated on

DATENAME(datepart, date) returns an nvarchar value for the requested part of a date or time. It returns names such as a month or weekday according to the session language; numeric parts such as year, quarter, or day are returned as strings. For an integer result, use DATEPART() instead. See Microsoft’s DATENAME documentation.

Syntax

DATENAME(datepart, date)
  • datepart is a supported literal such as year, quarter, month, day, weekday, or hour. It cannot be supplied as a variable.
  • date is an expression with a supported date or time type, such as date, datetime2, datetimeoffset, smalldatetime, or time.

Return month and weekday names

DATENAME() returns text. The names depend on the session language, so the same date can produce different month and weekday names under a different SET LANGUAGE setting.

SET LANGUAGE English;
DECLARE @date_value date = '2026-04-21';

SELECT DATENAME(month, @date_value) AS month_name,
       DATENAME(weekday, @date_value) AS weekday_name;

Result:

month_name weekday_name
April Tuesday

Group sales by year and month name

When grouping by a month name, include the year so that January in different years is not combined. Use date parts for chronological ordering:

SELECT DATENAME(year, SaleDate) AS year_name,
       DATENAME(month, SaleDate) AS month_name,
       SUM(SalesAmount) AS total_sales
FROM Sales
GROUP BY DATENAME(year, SaleDate), DATENAME(month, SaleDate),
         DATEPART(year, SaleDate), DATEPART(month, SaleDate)
ORDER BY DATEPART(year, SaleDate), DATEPART(month, SaleDate);

Use DATEDIFF() to count date-part boundaries between two values; DATENAME() returns labels and is not a duration calculator.