Quick Ref.
Functions
date
number
string
Data Types
date
number
string
Compatibility
DATEPART(YEAR, d)
Engine OK Alternative
mysql no EXTRACT(YEAR FROM d)
oracle no EXTRACT(YEAR FROM d)
postgres no EXTRACT(YEAR FROM d)
sqlserver yes DATEPART(YEAR,d)

DATEPART

DATEPART allows you to retrieve components of a date.

You can extract also YEAR, MONTH, DAY, HOUR, MINUTE, SECOND.

 DATEPART(YEAR, d)    DATEPART(MONTH, d)
 DATEPART(DAY, d)     DATEPART(HOUR, d)
 DATEPART(MINUTE, d)  DATEPART(SECOND, d) 

In this example you get the year and the month from the date whn.


Results
See also: