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