Home > Database > Mysql Tutorial > How to get the month in mysql?

How to get the month in mysql?

青灯夜游
Release: 2020-10-12 10:25:36
Original
15132 people have browsed it

You can use the MONTH() function in mysql to get the month, which will get the month value from the specified date value. The MONTH() function needs to accept the date parameter, the syntax format is "MONTH(date);", and returns the month corresponding to the specified date, ranging from "1 to 12".

How to get the month in mysql?

(Recommended tutorial: mysql video tutorial)

The MONTH(date) function in MySQL returns the corresponding date of the specified date Month, ranging from 1 to 12.

MONTH() function needs to accept the date parameter and return the month of the date.

The syntax format is as follows:

MONTH(date);
Copy after login

Example:

Use the MONTH() function to return the month in the specified date, enter The SQL statement and execution results are shown below.

mysql> SELECT MONTH('2020-10-12');
+---------------------+
| MONTH('2020-10-12') |
+---------------------+
|                  10 |
+---------------------+
1 row in set (0.00 sec)
Copy after login

It can be seen from the running results that the corresponding month of 2020-10-12 is 10.

Extended information

1. Get the current date--CURDATE()

SELECT  CURDATE();
或
select DATE(CURDATE());
Copy after login

2. Get the current time--NOW()

SELECT  NOW()
Copy after login

3. Get the current year--YEAR()

select YEAR(CURDATE());
Copy after login

4. Get the current month--MONTH()

select MONTH(CURDATE());
Copy after login

5. Get In January of that year

select CONCAT(YEAR(CURDATE()),'-','01');
Copy after login

related recommendations: php training

The above is the detailed content of How to get the month in mysql?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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