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
Release: 2023-08-30 13:41:06
forward
1525 people have browsed it

我们如何从 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)
Copy after login

(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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template