DATEPART Function [Date and Time]

Returns an integer value for the specified part of a date/time value.

Syntax

DATEPARTdate-part, date-expression )

Parameters

Parameters

Parameter

Description

date-part

The date part to be returned.

date-expression

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

Returns

INT

Example

The following statement returns the value 5:

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

Usage

The DATE, TIME, and DTTM indexes do not support some date parts (Calyearofweek, Calweekofyear, Caldayofweek, Dayofyear, Millisecond, Microsecond).

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]
DATENAME Function [Date and Time]
DATEROUND Function [Date and Time]
Date Parts