SQL EXTRACT() return a single part of a date/time(likes year, month, day, hour, minute)
Table – orders
+—–+—–+——-+———————+
| oid | uid | items | date |
+—–+—–+——-+———————+
| 1 | 1 | AAAA | 2007-05-16 00:00:00 |
+—–+—–+——-+———————+
Example
mysql> SELECT EXTRACT(YEAR FROM date) FROM orders;
+————————-+
| EXTRACT(YEAR FROM date) |
+————————-+
| 2007 |
+————————-+
1 row in set (0.00 sec)
Unit
MICROSECOND
SECOND
MINUTE
HOUR
DAY
WEEK
MONTH
QUARTER
YEAR
SECOND_MICROSECOND
MINUTE_MICROSECOND
MINUTE_SECOND
HOUR_MICROSECOND
HOUR_SECOND
HOUR_MINUTE
DAY_MICROSECOND
DAY_SECOND
DAY_MINUTE
DAY_HOUR