MySQL DAYNAME() Function

MySQL DAYNAME() Function

MySQL DAYNAME() Function; Through this tutorial, we will learn how to get weekday name using the MySQL dayname() function with the help of examples.

Sometimes we need to get the day name of the week in queries, at that time we will use to mysql dayname() function. It will return string value.

MySQL DAYNAME() Function

In MySQL, DAYNAME function is used to return the weekday name from a given date.

Let’s understand by example, If you pass the date “2019-07-11” in MySQL dayname() function, it will returns day name like Thursday.

Syntax of MySQL DAYNAME() Function

The mysql dayname() function syntax; as shown below:

DAYNAME(date)

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

Examples of MySQL DAYNAME() Function

Let’s take some examples of MySQL dayname function; as shown below:

Example-1

First simple example to demonstrate.

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

Output-1

 +---------+
 | Result  |
 +---------+
 |Thursday |
 +---------+

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 names of a table in the database. In that case we use dayname() with mysql queries.

Next, we take example-2, in this example we will fetch dayname of database table name users where column name is created_at.

 SELECT
 created_at AS create_date,
 DAYNAME(created_at) AS week_day_name
 FROM users
 WHERE id = 1;

Output-2

 +---------------------+--------------+
 | create_date         |week_day_name |
 +---------------------+--------------+
 | 2019-07-11 11:30:37 | Thursday     |
 +---------------------+--------------+

Example-3 | Current Date/Time

Now we take new example using current date with DAYNAME() function. It will return weekday name from the current date & time.

 SELECT 
 NOW(),
 DAYNAME(NOW());

Output-3

 +---------------------+----------------+
 | NOW()               | DAYNAME(NOW()) |
 +---------------------+----------------+
 | 2018-07-11 19:05:41 | Thursday       |
 +---------------------+----------------+

Example-4 | CURDATE Function

Next, we will take another example of DAYNAME() with CURDATE() function. Which is returns only the weekday name.

 SELECT 
CURDATE(),
DAYNAME(CURDATE());

Output-4

 +------------+--------------------+
 | CURDATE()  | DAYNAME(CURDATE()) |
 +------------+--------------------+
 | 2019-07-11 | Thursday           |
 +------------+--------------------+

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 DAYNAME() again.

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

Output-5

+-----------+
| Result    |
+-----------+
|  lundi    |
+-----------+

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 DAYNAME() function with various examples.

Recommended MySQL Tutorials

If you have any questions or thoughts to share, use the comment form below to reach us.

AuthorAdmin

My name is Devendra Dode. I am a full-stack developer, entrepreneur, and owner of Tutsmake.com. I like writing tutorials and tips that can help other developers. I share tutorials of 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 from a starting stage. As well as demo example.

Leave a Reply

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