Last update: Download PDF Edit

The DATEPART function retrieves a specified element from a date/time values. This element is of type integer.

The syntax is as follows:

DATEPART ( datepart , date_expression )

datepart Specifies the part of the date/time value to retrieve. This can be one of the following:

datepartdefinitionexample when used for Friday July 1, 2005, 16:34:20
YEAR 2005
QUARTER1, 2, 3 or 43
MONTH1 to 127
DAYOFYEAR1 to 366 
DAY1 to 315
WEEK1 to 53 (depends on the database implementation) 
WEEKDAY1 to 7 (1 = Sunday, 7 = Saturday)6
HOUR0 to 2316
MINUTE0 to 5934
SECOND0 to 5920

date_expression Specifies the date to retrieve an element from. This should be formatted in an expression which resolves to a date/time value.