MySQL MONTHNAME() Function : Get Month Name From Date

Monthname() function in mysql; Through this tutorial, i am going to show you how to get the month name from a date using MySQL monthname() function with the help of examples.

MySQL MONTHNAME() Function

MONTHNAME() function in MySQL is used to find month name from the given date. It Returns 0 when MONTH part for the date is 0 or greater than 12 otherwise it returns month name between January to December.

Syntax of monthname() function in mysql

The MONTHNAME() function syntax is:

MONTHNAME(date)

Here date is the date value that you want return the month name from.

Example 1 – MySQL MONTHNAME() Function

To get month name from date using the mysql monthname() function; as follows:

SELECT MONTHNAME('2019-07-11') AS 'Result';

Output-1

 +---------+
 | Result  |
 +---------+
 |July     |
 +---------+

Example 2 – MySQL get month name from date in Query

To get MONTH NAME of database table name users where column name is created_at; as follows:

 SELECT
 created_at AS create_date,
 MONTHNAME(created_at) AS month_name
 FROM users
 WHERE id = 1;

Output-2

 +---------------------+--------------+
 | create_date         |month_name    |
 +---------------------+--------------+
 | 2019-07-11 11:30:37 | july         |
 +---------------------+--------------+

Example 3 – MySQL MONTHNAME() with Now() Function

To get current date with MONTHNAME() function. It will return month name from the current date & time; as follows:

 SELECT 
 NOW(),
 MONTHNAME(NOW());

Output-3

 +---------------------+-------------------+
 | NOW()               | MONTHNAME(NOW())  |
 +---------------------+-------------------+
 | 2018-07-11 19:05:41 | July              |
 +---------------------+-------------------+

Example 4 – MySQL MONTHNAME() with CURDATE() Function

Take example using MONTHNAME() with CURDATE() function. Which is returns month name; as follows:

 SELECT 
CURDATE(),
MONTHNAME(CURDATE());

Output-4

 +------------+----------------------+
 | CURDATE()  | MONTHNAME(CURDATE()) |
 +------------+----------------------+
 | 2019-07-11 | July                 |
 +------------+----------------------+

Example 5 – MySQL MONTHNAME() with Local () Function

The language used for the month name is controlled by the lc_time_names system variable. Here’s an example of changing the value of that variable, and then running MONTHNAME() again.

 SET lc_time_names = 'fr_FR';
 SELECT MONTHNAME('2021-12-07') AS 'Result';

Output-5

+-----------+
| Result    |
+-----------+
| décembre  |
+-----------+

In this example, We changed the lc_time_names variable to fr_FR which means  French – France.

List of MySQL locale

The following table shows the valid locales for lc_time_names supported by MySQL:

Albanian – Albaniasq_AL
Arabic – Algeriaar_DZ
Arabic – Bahrainar_BH
Arabic – Egyptar_EG
Arabic – Indiaar_IN
Arabic – Iraqar_IQ
Arabic – Jordanar_JO
Arabic – Kuwaitar_KW
Arabic – Lebanonar_LB
Arabic – Libyaar_LY
Arabic – Moroccoar_MA
Arabic – Omanar_OM
Arabic – Qatarar_QA
Arabic – Saudi Arabiaar_SA
Arabic – Sudanar_SD
Arabic – Syriaar_SY
Arabic – Tunisiaar_TN
Arabic – United Arab Emiratesar_AE
Arabic – Yemenar_YE
Basque – Basqueeu_ES
Belarusian – Belarusbe_BY
Bulgarian – Bulgariabg_BG
Catalan – Spainca_ES
Chinese – Chinazh_CN
Chinese – Hong Kongzh_HK
Chinese – Taiwan Province of Chinazh_TW
Croatian – Croatiahr_HR
Czech – Czech Republiccs_CZ
Danish – Denmarkda_DK
Dutch – Belgiumnl_BE
Dutch – The Netherlandsnl_NL
English – Australiaen_AU
English – Canadaen_CA
English – Indiaen_IN
English – New Zealanden_NZ
English – Philippinesen_PH
English – South Africaen_ZA
English – United Kingdomen_GB
English – United Statesen_US
English – Zimbabween_ZW
Estonian – Estoniaet_EE
Faroese – Faroe Islandsfo_FO
Finnish – Finlandfi_FI
French – Belgiumfr_BE
French – Canadafr_CA
French – Francefr_FR
French – Luxembourgfr_LU
French – Switzerlandfr_CH
Galician – Spaingl_ES
German – Austriade_AT
German – Belgiumde_BE
German – Germanyde_DE
German – Luxembourgde_LU
German – Switzerlandde_CH
Greek – Greeceel_GR
Gujarati – Indiagu_IN
Hebrew – Israelhe_IL
Hindi – Indiahi_IN
Hungarian – Hungaryhu_HU
Icelandic – Icelandis_IS
Indonesian – Indonesiaid_ID
Italian – Italyit_IT
Italian – Switzerlandit_CH
Japanese – Japanja_JP
Korean – Republic of Koreako_KR
Latvian – Latvialv_LV
Lithuanian – Lithuanialt_LT
Macedonian – FYROMmk_MK
Malay – Malaysiams_MY
Mongolia – Mongolianmn_MN
Norwegian – Norwayno_NO
Norwegian(Bokmål) – Norwaynb_NO
Polish – Polandpl_PL
Portugese – Brazilpt_BR
Portugese – Portugalpt_PT
Romanian – Romaniaro_RO
Russian – Russiaru_RU
Russian – Ukraineru_UA
Serbian – Yugoslaviasr_RS
Slovak – Slovakiask_SK
Slovenian – Sloveniasl_SI
Spanish – Argentinaes_AR
Spanish – Boliviaes_BO
Spanish – Chilees_CL
Spanish – Columbiaes_CO
Spanish – Costa Ricaes_CR
Spanish – Dominican Republices_DO
Spanish – Ecuadores_EC
Spanish – El Salvadores_SV
Spanish – Guatemalaes_GT
Spanish – Hondurases_HN
Spanish – Mexicoes_MX
Spanish – Nicaraguaes_NI
Spanish – Panamaes_PA
Spanish – Paraguayes_PY
Spanish – Perues_PE
Spanish – Puerto Ricoes_PR
Spanish – Spaines_ES
Spanish – United Stateses_US
Spanish – Uruguayes_UY
Spanish – Venezuelaes_VE
Swedish – Finlandsv_FI
Swedish – Swedensv_SE
Tamil – Indiata_IN
Telugu – Indiate_IN
Thai – Thailandth_TH
Turkish – Turkeytr_TR
Ukrainian – Ukraineuk_UA
Urdu – Pakistanur_PK
Vietnamese – Viet Namvi_VN

Conclusion

MySQL get month name from a date tutorial, You have learned how to use MONTHNAME() function with various examples.

Leave a Comment