MySQL MONTH() Function
The MONTH()
function in MySQL extracts the month from a date or datetime value. It's a very handy function for working with dates and performing month-based analysis or filtering.
MONTH(): Definition and Usage
MONTH()
takes a date or datetime value as input and returns an integer representing the month (1 for January, 2 for February, ..., 12 for December). This is helpful for various data manipulation and reporting tasks that involve monthly data.
Syntax
Syntax
MONTH(date)
Parameter Values
Parameter | Description |
---|---|
date |
The date or datetime value from which to extract the month. This is required. |
Examples
Extracting the Month from a DATE Value
This example extracts the month (6) from the date "2017-06-15".
Syntax
SELECT MONTH("2017-06-15");
Output
6
Extracting the Month from a DATETIME Value
This demonstrates that MONTH()
works correctly with datetime values, ignoring the time portion.
Syntax
SELECT MONTH("2017-06-15 09:34:21");
Output
6
Extracting the Current Month
This gets the current month's number from the system.
Syntax
SELECT MONTH(CURDATE());
Output
(The current month will be displayed here as a number between 1 and 12.)