datename

Returns the specified datepart of the specified date or time as a character string.

Syntax

datename(datepart {date | time | bigtime | datetime | bigdatetime})

Parameters

Examples

Usage

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

  • Takes a date, time, bigdatetime, bigtime, datetime, or smalldatetime value as its second argument

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

See also select, where clause in Reference Manual: Commands.

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute datename.

Related concepts
Date and Time Datatypes
Related reference
dateadd
datename
datepart
getdate