Home >Database >Mysql Tutorial >How can we get month and day from given date in MySQL?

How can we get month and day from given date in MySQL?

WBOY
WBOYforward
2023-08-30 13:41:061490browse

我们如何从 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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete