MySQL MONTHNAME() Function Examples

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 – 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

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.

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *