DATENAME Function [Date and Time]

Returns the name of the specified part (such as the month “June”) of a date/time value, as a character string.

Syntax

DATENAMEdate-part, date-expression )

Parameters

Parameters

Parameter

Description

date-part

The date part to be named.

date-expression

The date for which the date part name is to be returned. The date must contain the requested date-part.

Returns

VARCHAR

Example

The following statement returns the value May:

SELECT DATENAME( MONTH , '1987/05/02' )
FROM iq_dummy
The following statement returns the value 722,001:
SELECT DATENAME(MICROSECOND, '2009-11-10
14:57:52.722001') FROM iq_dummy
The following statement returns the value 777,777:
SELECT DATENAME(MICROSECOND, '2000/07/07
07:07:07.777777') FROM iq_dummy
The following statement returns the value 33,189:
SELECT DATENAME(MCS, '2009-11-03 11:10:42.033189')
FROM iq_dummy

Usage

DATENAME returns a character string, even if the result is numeric, such as 23, for the day.

Standards and Compatibility

  • SQL—Transact-SQL extension to ISO/ANSI SQL grammar.

  • Sybase—Compatible with Adaptive Server Enterprise.

Related reference
DATEADD Function [Date and Time]
DATECEILING Function [Date and Time]
DATEDIFF Function [Date and Time]
DATEFLOOR Function [Date and Time]
DATEPART Function [Date and Time]
DATEROUND Function [Date and Time]
Date Parts