EXTRACT(unit FROM date): extracts parts from the date rather than performing date arithmetic : EXTRACT « Date Time Functions « MySQL Tutorial






The following table shows the expected form of the expr argument for each unit value.

unit ValueExpected expr Format
MICROSECONDMICROSECONDS
SECONDSECONDS
MINUTEMINUTES
HOURHOURS
DAYDAYS
WEEKWEEKS
MONTHMONTHS
QUARTERQUARTERS
YEARYEARS
SECOND_MICROSECOND'SECONDS.MICROSECONDS'
MINUTE_MICROSECOND'MINUTES.MICROSECONDS'
MINUTE_SECOND'MINUTES:SECONDS'
HOUR_MICROSECOND'HOURS.MICROSECONDS'
HOUR_SECOND'HOURS:MINUTES:SECONDS'
HOUR_MINUTE'HOURS:MINUTES'
DAY_MICROSECOND'DAYS.MICROSECONDS'
DAY_SECOND'DAYS HOURS:MINUTES:SECONDS'
DAY_MINUTE'DAYS HOURS:MINUTES'
DAY_HOUR'DAYS HOURS'
YEAR_MONTH'YEARS-MONTHS'










14.17.EXTRACT
14.17.1.EXTRACT(unit FROM date): extracts parts from the date rather than performing date arithmetic
14.17.2.SELECT EXTRACT(YEAR FROM '1999-07-02');
14.17.3.SELECT EXTRACT(YEAR_MONTH FROM '1999-07-02 01:02:03');
14.17.4.SELECT EXTRACT(DAY_MINUTE FROM '1999-07-02 01:02:03');
14.17.5.SELECT EXTRACT(MICROSECOND FROM '2003-01-02 10:30:00.000123');
14.17.6.SELECT EXTRACT(SECOND FROM '2003-01-02 10:30:00.000123');
14.17.7.SELECT EXTRACT(MINUTE FROM '2003-01-02 10:30:00.000123');
14.17.8.SELECT EXTRACT(HOUR FROM '2003-01-02 10:30:00.000123');
14.17.9.SELECT EXTRACT(DAY FROM '2003-01-02 10:30:00.000123');
14.17.10.SELECT EXTRACT(WEEK FROM '2003-01-02 10:30:00.000123');
14.17.11.SELECT EXTRACT(MONTH FROM '2003-01-02 10:30:00.000123');
14.17.12.SELECT EXTRACT(QUARTER FROM '2003-01-02 10:30:00.000123');
14.17.13.SELECT EXTRACT(SECOND_MICROSECOND FROM '2003-01-02 10:30:00.000123');
14.17.14.SELECT EXTRACT(MINUTE_MICROSECOND FROM '2003-01-02 10:30:00.000123');
14.17.15.SELECT EXTRACT(MINUTE_SECOND FROM '2003-01-02 10:30:00.000123');
14.17.16.SELECT EXTRACT(HOUR_MICROSECOND FROM '2003-01-02 10:30:00.000123');
14.17.17.SELECT EXTRACT(HOUR_SECOND FROM '2003-01-02 10:30:00.000123');
14.17.18.SELECT EXTRACT(HOUR_MINUTE FROM '2003-01-02 10:30:00.000123');
14.17.19.SELECT EXTRACT(DAY_MICROSECOND FROM '2003-01-02 10:30:00.000123');
14.17.20.SELECT EXTRACT(DAY_SECOND FROM '2003-01-02 10:30:00.000123');
14.17.21.SELECT EXTRACT(DAY_HOUR FROM '2003-01-02 10:30:00.000123');