MySQL DAYNAME() Function

MySQL DAYNAME() Function; Through this tutorial, i am going to show you how to get weekday name from date using the MySQL dayname() function with the help of examples.

MySQL DAYNAME() Function

 The MySQL DAYNAME function returns the weekday name from a date.

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 1 – MySQL DAYNAME() Function

Now, i will take first example to get day name from a date using dayname function in mysql; as follows:

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

Output-1

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

Examples 2 – MySQL DAYNAME() Function

To fetch a record / data from the mysql database table with week day name using mysql query; as follows:

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

Examples 3 – MySQL DAYNAME() with Now() Function

Current date with DAYNAME() function. It will return weekday name from the current date & time; as follows:

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

Output-3

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

Examples 4 – MySQL DAYNAME() with CURDATE() Function

Take an example using DAYNAME() with CURDATE() function. Which is returns only the weekday name; as follows:

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

Output-4

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

Examples 5 – MySQL DAYNAME() 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 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

Through this tutorial, You have learned how to use DAYNAME() function with various examples.

Be First to Comment

Leave a Reply

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