Monthname() function in mysql; Through this tutorial, we will learn how to get the month name of a date using MySQL monthname() function.
Sometime we need to get month name of given date in queries that time we can use to MONTHNAME() function. We will take some example of mysql monthname() function with CURDATE(), NOW() etc.
Let’s see, if you give a date of 2019-07-11 in monthname() function, it will return the July month. The MySQL monthname() function returns only string value.
MySQL MONTHNAME() Function
In MySQL, MONTHNAME function is used to return the month name from a given date.
For e.g., If you pass the date “2019-07-11” in MySQL MONTHNAME() function, The MySQL monthname() will return month name like July.
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.
Examples of monthname() function in mysql
Now we take different different type of examples of MONTHNAME function. See below all the examples one by one.
Example-1
First simple example to demonstrate.
SELECT MONTHNAME('2019-07-11') AS 'Result';
Output-1
+---------+ | Result | +---------+ |July | +---------+
Example-2 | Database Example
For some time we want to fetch a record / data from the mysql database table. When we need to get the name of month a table in the database. In that case we use MONTHNAME() with mysql queries.
Next, we take example-2, in this example we will fetch MONTH NAME of database table name users where column name is created_at.
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 | Current Date/Time
Now we take new example using current date with MONTHNAME() function. It will return month name from the current date & time.
SELECT NOW(), MONTHNAME(NOW());
Output-3
+---------------------+-------------------+ | NOW() | MONTHNAME(NOW()) | +---------------------+-------------------+ | 2018-07-11 19:05:41 | July | +---------------------+-------------------+
Example-4 | CURDATE Function
Next, we will take another example of MONTHNAME() with CURDATE() function. Which is returns month name.
SELECT
CURDATE(),
MONTHNAME(CURDATE());
Output-4
+------------+----------------------+ | CURDATE() | MONTHNAME(CURDATE()) | +------------+----------------------+ | 2019-07-11 | July | +------------+----------------------+
Example-5 | Locale
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
Here, You have learned how to use MONTHNAME() function with various examples.
Recommended MySQL Tutorials
If you have any questions or thoughts to share, use the comment form below to reach us.