Home >Database >Mysql Tutorial >How can we get month and day from given date in MySQL?
Influx can be done in two ways -
(A) With the help of EXRACT() function - EXTRACT() function can extract values from MySQL TIMESTAMP Get any part of it. Below is an example to get the month and day from a given date.
mysql> Select EXTRACT(Month from '2017-10-22') AS 'MONTH'; +-------+ | MONTH | +-------+ | 10 | +-------+ 1 row in set (0.00 sec) mysql> Select EXTRACT(day from '2017-10-22')AS 'DAY'; +------+ | DAY | +------+ | 22 | +------+ 1 row in set (0.00 sec)
(B) With the help of MONTH() or DAY() function- We can get the values of MONTH and DAY from a given date using MONTH() and DAY() functions as follows-
mysql> Select DAY('2017-10-22')AS 'DAY'; +------+ | DAY | +------+ | 22 | +------+ 1 row in set (0.00 sec) mysql> Select MONTH('2017-10-22')AS 'MONTH'; +-------+ | MONTH | +-------+ | 10 | +-------+ 1 row in set (0.00 sec)
The above is the detailed content of How can we get month and day from given date in MySQL?. For more information, please follow other related articles on the PHP Chinese website!