从MYSQL中的索引号获取工作日名称 [英] Get Weekday name from index number in MYSQL

查看:96
本文介绍了从MYSQL中的索引号获取工作日名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表将0-6作为工作日的值存储,我想显示工作日名称。例如。如果值为 0 ,它将显示星期日,如果值为 1 ,同样会显示 Monday
有没有内置的MySQL函数从索引中获取日期名称?

I have a table which stores 0-6 as weekday value, and I want to display weekday name. E.g. if value is 0, it will display Sunday, if value is 1, it will display Monday, likewise. Is there any inbuilt MySQL function for getting day name from Index?

感谢提前!

推荐答案

DAYNAME(date_value)在MySql中可用;然而,这需要一个日期,而不是int。因此,如果您有日期可用,您可以使用 DAYNAME(CURDATE()) DAYNAME('2014-01-07')等。

DAYNAME( date_value ) is available in MySql; however, this takes a date, not an int. So if you have the date available, you can just use DAYNAME(CURDATE()), DAYNAME('2014-01-07'), etc.

如果所有可用的都是表示工作日的int,则CASE语句可能是您最好的选择。

If all you have available is the int representing the weekday, then a CASE statement might be your best bet.

CASE WHEN 0 THEN'星期天'
当时为'星期一'
.....
ELSE''
END

这篇关于从MYSQL中的索引号获取工作日名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆