The MySQL MONTHNAME() function returns the month name for the given date. It returns the month name between January and December or 0 if month part for the date is 0 or greater than 12.
Syntax
MONTHNAME function syntax is:
MONTHNAME(date)
Parameter:
This MONTHNAME() function accepts one parameter as mentioned above and described below :
- date: The date or datetime from which we want to extract the month name.
MySQL MONTHNAME() Function Examples
Let's look at some examples of the MONTHNAME function in MySQL.
Example 1
Finding the Current Month name Using MONTHNAME() Function.
SELECT MONTHNAME(NOW()) AS Current_Month;
Output :
| Current_Month |
|---|
| November |
Example 2
Finding the Month name from given datetime Using MONTHNAME() Function.
SELECT MONTHNAME('2015-01-26 08:09:22') AS MONTHNAME;
Output :
| MONTHNAME |
|---|
| January |
Example 3
Finding the Month name from given datetime Using MONTHNAME() Function when the date is NULL.
SELECT MONTHNAME(NULL) AS MONTHNAME;
Output :
| MONTHNAME |
|---|
| NULL |