The EXTRACT function extracts parts from a date and gives a datetime value.
Format: EXTRACT(date_part FROM expression)
Date_parts are:
CENTURY ................................. PostgreSQL .................
DAY ............. Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
DAY_HOUR ................... MySQL ...................................
DAY_MINUTE ................. MySQL ...................................
DAY_SECOND ................. MySQL ...................................
DAYOFYEAR .......................................... SQL Server ......
DECADE .................................. PostgreSQL .................
DOW (day of week) ....................... PostgreSQL .................
DOY (day of year) ....................... PostgreSQL .................
EPOCH ................................... PostgreSQL .................
HOUR ............ Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
HOUR_MINUTE ................ MySQL ...................................
HOUR_SECOND ................ MySQL ...................................
MICROSECONDS ........... DB2 ............ PostgreSQL .................
MILLENNIUM .............................. PostgreSQL .................
MILLISECONDS ............................ PostgreSQL SQL Server ......
MINUTE .......... Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
MINUTE_SECOND .............. MySQL ...................................
MONTH ........... Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
MONTHNAME ....... Access .............................................
QUARTER ................................. PostgreSQL SQL Server ......
SECOND .......... Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
TIMEZONE_ABBR .................... Oracle ............................
TIMEZONE_HOUR .................... Oracle PostgreSQL .......... Sybase
TIMEZONE_MINUTE .................. Oracle PostgreSQL .......... Sybase
TIMEZONE_REGION .................. Oracle ............................
WEEK ................... DB2 ..... Oracle PostgreSQL SQL Server ......
WEEKDAY ......... Access ........................... SQL Server ......
WEEKDAYNAME ..... Access .............................................
YEAR ............ Access DB2 MySQL Oracle PostgreSQL SQL Server Sybase
YEAR_MONTH ................. MySQL ...................................
Example: SELECT EXTRACT(DAY FROM ‘2056-01-11′) FROM TABLEA;
Result:
                   
> A date or time range returns all the values inbetween, such as DAY_SECOND gives DAY, HOUR, MINUTE, SECOND (11 09:15:00).
> MySQL, Oracle, PostgreSQL, and Sybase support EXTRACT.
> Access, and SQL Server do not support EXTRACT. Instead, they use DATEPART(date_part, expression).
Access also supports DATEADD, DATEDIFF, DATESERIAL, DATEVALUE, TIMESERIAL, and TIMEVALUE.
> DB2 does not support EXTRACT. Instead, it uses the date_part name as the functions, such as DAY(expression).
Other DB2 functions include LOCAL_TIME, and LOCAL_TIMESTAMP.
> MySQL also supports NOW().