datename

Description

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

Syntax

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

Parameters

datepart

is a date part or abbreviation. For a list of the date parts and abbreviations recognized by Adaptive Server, see Transact-SQL Users Guide.

date_expression

is an expression of type datetime, smalldatetime, bigdatetime, bigtime, time or a character string in a datetime format.

Examples

Example 1

Finds the month name of a bigdatetime:

declare @a bigdatetime
select @a = "apr 12, 0001 00:00:00.010101"
select datename(mm, @a)
------------------------------
April

Example 2

Assumes a current date of November 20, 2000:

select datename(month, getdate())
November

Example 3

Finds the month name of a date:

declare @a date
select @a = "apr 12, 0001"
select datename(mm, @a)
------------------------------
    April

Example 4

Finds the seconds of a time:

declare @a time
select @a = "20:43:22"
select datename(ss, @a)
------------------------------
    22

Usage

Standards

ANSI SQL – Compliance level: Transact-SQL extension.

Permissions

Any user can execute datename.

See also

Datatypes Date and time datatypes

Commands select, where clause

Functions dateadd, datename, datepart, getdate