几个星期相关的函数
WEEKDAY()
取值为0~6,对应星期一到星期日,每周以星期一为第一天
DAYOFWEEK()
取值为1~7,对应星期日到星期六,每周以星期日为第一天
DAYNAME()
取值为Sunday~Saturday,对应星期日到星期六,第一天是星期日;
该函数与参数lc_time_names有关,如果设置此参数值为"zh_CN",则得到对应的中文名称“星期日”~“星期六”
示例:
mysql> set @day='2017-01-02';
Query OK, 0 rows affected (0.00 sec)
mysql> select weekday(@day),dayofweek(@day),dayname(@day);
+---------------+-----------------+---------------+
| weekday(@day) | dayofweek(@day) | dayname(@day) |
+---------------+-----------------+---------------+
| 0 | 2 | Monday |
+---------------+-----------------+---------------+
2017-01-02是星期一,使用这三个函数分别得到的是0,2,Monday
修改lc_time_names参数后,得到中文名称:
mysql> set lc_time_names='zh_CN';
Query OK, 0 rows affected (0.00 sec)
mysql> select weekday(@day),dayofweek(@day),dayname(@day);
+---------------+-----------------+---------------+
| weekday(@day) | dayofweek(@day) | dayname(@day) |
+---------------+-----------------+---------------+
| 0 | 2 | 星期一 |
+---------------+-----------------+---------------+