Returns an integer value for the specified part of a date/time value.
DATEPART ( date-part, date-expression )
date-part The date part to be returned.
For a complete listing of allowed date parts, see “Date parts”.
date-expression The date for which the part is to be returned. The date must contain the date-part field.
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
The DATE, TIME, and DTTM indexes do not support some date parts (Calyearofweek, Calweekofyear, Caldayofweek, Dayofyear, Millisecond, Microsecond).