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 – Albania | sq_AL |
Arabic – Algeria | ar_DZ |
Arabic – Bahrain | ar_BH |
Arabic – Egypt | ar_EG |
Arabic – India | ar_IN |
Arabic – Iraq | ar_IQ |
Arabic – Jordan | ar_JO |
Arabic – Kuwait | ar_KW |
Arabic – Lebanon | ar_LB |
Arabic – Libya | ar_LY |
Arabic – Morocco | ar_MA |
Arabic – Oman | ar_OM |
Arabic – Qatar | ar_QA |
Arabic – Saudi Arabia | ar_SA |
Arabic – Sudan | ar_SD |
Arabic – Syria | ar_SY |
Arabic – Tunisia | ar_TN |
Arabic – United Arab Emirates | ar_AE |
Arabic – Yemen | ar_YE |
Basque – Basque | eu_ES |
Belarusian – Belarus | be_BY |
Bulgarian – Bulgaria | bg_BG |
Catalan – Spain | ca_ES |
Chinese – China | zh_CN |
Chinese – Hong Kong | zh_HK |
Chinese – Taiwan Province of China | zh_TW |
Croatian – Croatia | hr_HR |
Czech – Czech Republic | cs_CZ |
Danish – Denmark | da_DK |
Dutch – Belgium | nl_BE |
Dutch – The Netherlands | nl_NL |
English – Australia | en_AU |
English – Canada | en_CA |
English – India | en_IN |
English – New Zealand | en_NZ |
English – Philippines | en_PH |
English – South Africa | en_ZA |
English – United Kingdom | en_GB |
English – United States | en_US |
English – Zimbabwe | en_ZW |
Estonian – Estonia | et_EE |
Faroese – Faroe Islands | fo_FO |
Finnish – Finland | fi_FI |
French – Belgium | fr_BE |
French – Canada | fr_CA |
French – France | fr_FR |
French – Luxembourg | fr_LU |
French – Switzerland | fr_CH |
Galician – Spain | gl_ES |
German – Austria | de_AT |
German – Belgium | de_BE |
German – Germany | de_DE |
German – Luxembourg | de_LU |
German – Switzerland | de_CH |
Greek – Greece | el_GR |
Gujarati – India | gu_IN |
Hebrew – Israel | he_IL |
Hindi – India | hi_IN |
Hungarian – Hungary | hu_HU |
Icelandic – Iceland | is_IS |
Indonesian – Indonesia | id_ID |
Italian – Italy | it_IT |
Italian – Switzerland | it_CH |
Japanese – Japan | ja_JP |
Korean – Republic of Korea | ko_KR |
Latvian – Latvia | lv_LV |
Lithuanian – Lithuania | lt_LT |
Macedonian – FYROM | mk_MK |
Malay – Malaysia | ms_MY |
Mongolia – Mongolian | mn_MN |
Norwegian – Norway | no_NO |
Norwegian(Bokmål) – Norway | nb_NO |
Polish – Poland | pl_PL |
Portugese – Brazil | pt_BR |
Portugese – Portugal | pt_PT |
Romanian – Romania | ro_RO |
Russian – Russia | ru_RU |
Russian – Ukraine | ru_UA |
Serbian – Yugoslavia | sr_RS |
Slovak – Slovakia | sk_SK |
Slovenian – Slovenia | sl_SI |
Spanish – Argentina | es_AR |
Spanish – Bolivia | es_BO |
Spanish – Chile | es_CL |
Spanish – Columbia | es_CO |
Spanish – Costa Rica | es_CR |
Spanish – Dominican Republic | es_DO |
Spanish – Ecuador | es_EC |
Spanish – El Salvador | es_SV |
Spanish – Guatemala | es_GT |
Spanish – Honduras | es_HN |
Spanish – Mexico | es_MX |
Spanish – Nicaragua | es_NI |
Spanish – Panama | es_PA |
Spanish – Paraguay | es_PY |
Spanish – Peru | es_PE |
Spanish – Puerto Rico | es_PR |
Spanish – Spain | es_ES |
Spanish – United States | es_US |
Spanish – Uruguay | es_UY |
Spanish – Venezuela | es_VE |
Swedish – Finland | sv_FI |
Swedish – Sweden | sv_SE |
Tamil – India | ta_IN |
Telugu – India | te_IN |
Thai – Thailand | th_TH |
Turkish – Turkey | tr_TR |
Ukrainian – Ukraine | uk_UA |
Urdu – Pakistan | ur_PK |
Vietnamese – Viet Nam | vi_VN |
Conclusion
MySQL get month name from a date tutorial, You have learned how to use MONTHNAME() function with various examples.