首页 > 代码库 > EXTRACT(type FROM date)

EXTRACT(type FROM date)

 

EXTRACT(type FROM date) 用于获取指定的日期值

mysql> SELECT EXTRACT(YEAR FROM 2016-07-02) AS col1,           # 当type为YEAR时,只返回年值    -> EXTRACT(YEAR_MONTH FROM 2016-07-02 01:02:03) AS col2,   # 当type为YEAR_MONTH时,返回年与月    -> EXTRACT(DAY_MINUTE FROM 2016-07-02 01:02:03) AS col3;   # 当type为DAY_MINUTE时,返回日、小时、分钟+------+--------+-------+| col1 | col2   | col3  |+------+--------+-------+| 2016 | 201607 | 20102 |+------+--------+-------+

 

 

 

   

 

EXTRACT(type FROM date)