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".
(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);
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)
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());
2. Get the current time--NOW()
SELECT NOW()
3. Get the current year--YEAR()
select YEAR(CURDATE());
4. Get the current month--MONTH()
select MONTH(CURDATE());
5. Get In January of that year
select CONCAT(YEAR(CURDATE()),'-','01');
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!