By using EXTRACT() function we can get the current date or part of a given date. Parts of the date can be obtained as year, month, day, hour, minute, second, and microsecond.
mysql> Select EXTRACT(Year from NOW()) AS YEAR; +-------+ | YEAR | +-------+ | 2017| +-------+ 1 row in set (0.00 sec)
The above MySQL query will get the year from the current date.
mysql> Select EXTRACT(Month from '2017-09-21')AS MONTH; +-------+ | MONTH | +-------+ | 9 | +-------+ 1 row in set (0.00 sec)
The above MySQL query will get the month for a given date.
The above is the detailed content of How to get part of date in MySQL?. For more information, please follow other related articles on the PHP Chinese website!