MySQL extract()函數
EXTRACT(unit FROM date)
EXTRACT() 函數使用的同種單位指示符如DATE_ADD() 或 DATE_SUB(),但是提取部分是從日期,而不是執行日期運算。
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)