EXTRACT()

EXTRACT(type FROM date)

La función EXTRACT() usa los mismos tipos de especificadores de intervalos que o , pero extrae partes de la fecha en lugar de realizar aritmética de fechas.

mysql>mysql> SELECT EXTRACT(YEAR FROM "1999-07-02");
+---------------------------------+
| EXTRACT(YEAR FROM "1999-07-02") |
+---------------------------------+
|                            1999 |
+---------------------------------+
1 row in set (0.00 sec)

mysql> SELECT EXTRACT(YEAR_MONTH FROM "1999-07-02 01:02:03");
+------------------------------------------------+
| EXTRACT(YEAR_MONTH FROM "1999-07-02 01:02:03") |
+------------------------------------------------+
|                                         199907 |
+------------------------------------------------+
1 row in set (0.00 sec)
mysql> SELECT EXTRACT(DAY_MINUTE FROM "1999-07-02 01:02:03");
+------------------------------------------------+
| EXTRACT(DAY_MINUTE FROM "1999-07-02 01:02:03") |
+------------------------------------------------+
|                                          20102 |
+------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT EXTRACT(MICROSECOND FROM "2003-01-02 10:30:00.00123");
        -> 123


suministrado por FreeFind
Valid HTML 4.0! Valid CSS!