Skip to main content

DAYNAME

Description

The DAYNAME function is used to calculate the name of the day (such as "Tuesday", etc.) corresponding to a date or time expression, returning a string type value.

You can set the language of the output result through the session variable lc_time_names, which is set to en_US by default, meaning the output is in English.

This function behaves consistently with the dayname function in MySQL

Syntax

DAYNAME(<date_or_time_expr>)

Parameters

ParameterDescription
<date_or_time_expr>A valid date expression that supports date/datetime types and strings in date-time format. For specific datetime and date formats, please refer to datetime conversion and date conversion

Return Value

Returns the day name corresponding to the date (string type)

Special cases:

  • If date_or_time_expr is NULL, returns NULL;

Examples


---Calculate day name corresponding to DATETIME type
select dayname('2007-02-03 00:00:00');

+--------------------------------+
| dayname('2007-02-03 00:00:00') |
+--------------------------------+
| Saturday |
+--------------------------------+

---Calculate day name corresponding to DATE type

select dayname('2023-10-01');
+-----------------------+
| dayname('2023-10-01') |
+-----------------------+
| Sunday |
+-----------------------+


---Parameter is NULL, returns NULL
select dayname(NULL);
+---------------+
| dayname(NULL) |
+---------------+
| NULL |
+---------------+

---Control the output language by setting `lc_time_names`
SET lc_time_names='zh_CN';
select dayname('2023-10-01');
+-----------------------+
| dayname('2023-10-01') |
+-----------------------+
| 星期日 |
+-----------------------+

SET lc_time_names='ar_ae';
select dayname('2023-10-01');
+-----------------------+
| dayname('2023-10-01') |
+-----------------------+
| الأحد |
+-----------------------+

Appendix: lc_time_names may be set to any of the following locale values(case insensitive).

Locale ValueMeaning
ar_AEArabic - United Arab Emirates
ar_BHArabic - Bahrain
ar_DZArabic - Algeria
ar_EGArabic - Egypt
ar_INArabic - India
ar_IQArabic - Iraq
ar_JOArabic - Jordan
ar_KWArabic - Kuwait
ar_LBArabic - Lebanon
ar_LYArabic - Libya
ar_MAArabic - Morocco
ar_OMArabic - Oman
ar_QAArabic - Qatar
ar_SAArabic - Saudi Arabia
ar_SDArabic - Sudan
ar_SYArabic - Syria
ar_TNArabic - Tunisia
ar_YEArabic - Yemen
be_BYBelarusian - Belarus
bg_BGBulgarian - Bulgaria
ca_ESCatalan - Spain
cs_CZCzech - Czech Republic
da_DKDanish - Denmark
de_ATGerman - Austria
de_BEGerman - Belgium
de_CHGerman - Switzerland
de_DEGerman - Germany
de_LUGerman - Luxembourg
el_GRGreek - Greece
en_AUEnglish - Australia
en_CAEnglish - Canada
en_GBEnglish - United Kingdom
en_INEnglish - India
en_NZEnglish - New Zealand
en_PHEnglish - Philippines
en_USEnglish - United States
en_ZAEnglish - South Africa
en_ZWEnglish - Zimbabwe
es_ARSpanish - Argentina
es_BOSpanish - Bolivia
es_CLSpanish - Chile
es_COSpanish - Colombia
es_CRSpanish - Costa Rica
es_DOSpanish - Dominican Republic
es_ECSpanish - Ecuador
es_ESSpanish - Spain
es_GTSpanish - Guatemala
es_HNSpanish - Honduras
es_MXSpanish - Mexico
es_NISpanish - Nicaragua
es_PASpanish - Panama
es_PESpanish - Peru
es_PRSpanish - Puerto Rico
es_PYSpanish - Paraguay
es_SVSpanish - El Salvador
es_USSpanish - United States
es_UYSpanish - Uruguay
es_VESpanish - Venezuela
et_EEEstonian - Estonia
eu_ESBasque - Spain
fi_FIFinnish - Finland
fo_FOFaroese - Faroe Islands
fr_BEFrench - Belgium
fr_CAFrench - Canada
fr_CHFrench - Switzerland
fr_FRFrench - France
fr_LUFrench - Luxembourg
gl_ESGalician - Spain
gu_INGujarati - India
he_ILHebrew - Israel
hi_INHindi - India
hr_HRCroatian - Croatia
hu_HUHungarian - Hungary
id_IDIndonesian - Indonesia
is_ISIcelandic - Iceland
it_CHItalian - Switzerland
it_ITItalian - Italy
ja_JPJapanese - Japan
ko_KRKorean - Republic of Korea
lt_LTLithuanian - Lithuania
lv_LVLatvian - Latvia
mk_MKMacedonian - North Macedonia
mn_MNMongolia - Mongolian
ms_MYMalay - Malaysia
nb_NONorwegian(Bokmål) - Norway
nl_BEDutch - Belgium
nl_NLDutch - The Netherlands
no_NONorwegian - Norway
pl_PLPolish - Poland
pt_BRPortugese - Brazil
pt_PTPortugese - Portugal
rm_CHRomansh - Switzerland
ro_RORomanian - Romania
ru_RURussian - Russia
ru_UARussian - Ukraine
sk_SKSlovak - Slovakia
sl_SISlovenian - Slovenia
sq_ALAlbanian - Albania
sr_RSSerbian - Serbia
sv_FISwedish - Finland
sv_SESwedish - Sweden
ta_INTamil - India
te_INTelugu - India
th_THThai - Thailand
tr_TRTurkish - Turkey
uk_UAUkrainian - Ukraine
ur_PKUrdu - Pakistan
vi_VNVietnamese - Vietnam
zh_CNChinese - China
zh_HKChinese - Hong Kong
zh_TWChinese - Taiwan