MySQL DAYNAME函数
时间:2019-11-20 08:52:22 来源:igfitidea点击:
简介:在本教程中,您将学习如何使用MySQL DAYNAME函数获取给定日期的工作日名称。
MySQL DAYNAME函数简介
MySQL DAYNAME函数返回指定日期的工作日名称。
以下说明了DAYNAME函数的语法:
DAYNAME(date);
DAYNAME函数接受1个参数,该参数是您要获取其工作日名称的日期。
如果日期为NULL或无效,例如2017-02-30,则DAYNAME函数将返回NULL。
MySQL DAYNAME函数示例
下面的示例返回2000年1月1日的工作日名称。
mysql> SELECT DAYNAME('2000-01-01') dayname; +----------+ | dayname | +----------+ | Saturday | +----------+ 1 row in set (0.00 sec)
默认情况下,MySQL以lc_time_names系统变量控制的语言返回工作日的名称。
mysql> SELECT @@lc_time_names; +-----------------+ | @@lc_time_names | +-----------------+ | en_US | +-----------------+ 1 row in set (0.00 sec)
如您所见,当前,语言环境设置为en_US。
要在特定语言环境中获取星期几的日期名称,您需要更改lc_time_names变量的值。
例如,以下语句将语言环境设置为法语:
mysql> SET @@lc_time_names = 'fr_FR'; Query OK, 0 rows affected (0.00 sec)
现在,让我们查询2000年1月1日的工作日名称:
mysql> SELECT DAYNAME('2000-01-01') dayname; +---------+ | dayname | +---------+ | samedi | +---------+ 1 row in set (0.00 sec)
如您所见,工作日名称已更改为法语。
下表显示了MySQL支持的lc_time_names的有效语言环境:
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 |
请参阅示例数据库中的以下订单表:
以下语句返回按2004年工作日名称分组的订单计数。
SELECT DAYNAME(orderdate) weekday, COUNT(*) total_orders FROM orders WHERE YEAR(orderdate) = 2004 GROUP BY weekday ORDER BY total_orders DESC;
周五下的订单数量最高,周日有两个订单。
在本教程中,您学习了如何使用MySQL DAYNAME函数来获取特定日期的工作日名称。