MariaDB MONTHNAME() Function
In MariaDB, MONTHNAME() is a built-in function that returns the month name for a given date.
It takes one argument, the date from which to extract the month name.
MariaDB MONTHNAME() Syntax
This is the syntax of the MariaDB MONTHNAME() function:
MONTHNAME(date)
Parameters
date-
Required. A date or datetime expression.
If you supply the wrong number of arguments, MariaDB will report an error: ERROR 1582 (42000): Incorrect parameter count in the call to native function 'MONTHNAME'.
Return value
The MariaDB MONTHNAME() function returns the name of the month for a given date. In the English environment, the return values will be one of the following values: January, February, March, April, May, June, July, August, September, October, November, December.
If the specified expression is not a valid date or datetime, the MONTHNAME() function will return NULL.
If the argument is NULL, the MONTHNAME() function will return NULL.
MariaDB MONTHNAME() Examples
Example 1
This statement shows the basic usage of the MariaDB MONTHNAME() function:
SELECT
MONTHNAME('2023-01-11'),
MONTHNAME('2023-01-11 10:11:12');
Output:
+-------------------------+----------------------------------+
| MONTHNAME('2023-01-11') | MONTHNAME('2023-01-11 10:11:12') |
+-------------------------+----------------------------------+
| January | January |
+-------------------------+----------------------------------+Example 2
This statement displays the names of all months:
SELECT
MONTHNAME('2023-01-01'),
MONTHNAME('2023-02-01'),
MONTHNAME('2023-03-01'),
MONTHNAME('2023-04-01'),
MONTHNAME('2023-05-01'),
MONTHNAME('2023-06-01'),
MONTHNAME('2023-07-01'),
MONTHNAME('2023-08-01'),
MONTHNAME('2023-09-01'),
MONTHNAME('2023-10-01'),
MONTHNAME('2023-11-01'),
MONTHNAME('2023-12-01')\G
Output:
MONTHNAME('2023-01-01'): January
MONTHNAME('2023-02-01'): February
MONTHNAME('2023-03-01'): March
MONTHNAME('2023-04-01'): April
MONTHNAME('2023-05-01'): May
MONTHNAME('2023-06-01'): June
MONTHNAME('2023-07-01'): July
MONTHNAME('2023-08-01'): August
MONTHNAME('2023-09-01'): September
MONTHNAME('2023-10-01'): October
MONTHNAME('2023-11-01'): November
MONTHNAME('2023-12-01'): DecemberExample 3 - Locale
The language used for month names is controlled by the value of the lc_time_names system variable.
To display month names in Chinese, set the locale to zh_CN:
SET lc_time_names = 'zh_CN';
SELECT MONTHNAME('2023-01-11');
Output:
+-------------------------+
| MONTHNAME('2023-01-11') |
+-------------------------+
| δΈζ |
+-------------------------+You can check the list of locales supported by MariaDB here.
Conclusion
In MariaDB, MONTHNAME() is a built-in function that returns the month name for a given date.