DATEPART function [Date and time]

Function

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

Syntax

DATEPART ( date-part, date-expression )

Parameters

date-part The date-part to be returned.

For a complete listing of allowed date-parts, see the section “Date parts”.

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

Example

The following statement returns the value 5.

SELECT DATEPART( month , '1987/05/02' ) FROM iq_dummy

Usage

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

Standards and compatibility