我有一个列,其中存储了星期几的1位数值:
0 = Sunday
1 = Monday
...
6 = Saturday我尝试了PHP date('l', $row['dow'])和MySQL DATE_FORMAT(dow, '%w'),但都没有返回星期几的单词。
在PHP或MySQL中可以做到这一点吗?或者我只需要创建一个array()变量?
发布于 2012-10-22 22:24:36
任何日期格式化函数都需要完整的日期/时间戳才能工作。只是一个"1“或"2”对这些函数没有任何意义(或者至少不是你想要的意思)。如果您存储的是完整的时间戳,则不需要再次单独存储星期几。否则,您将需要自己将这些毫无意义的数字转换为一个单词。
发布于 2012-10-22 22:22:49
$dow = date('l', strtotime("Sunday +{$row['dow']} days"));发布于 2012-10-22 22:21:25
在date( 'l' )上
l (lowercase 'L') - A full textual representation of the day of the week - Sunday through Saturday
您应该使用日期( 'w‘):
w - Numeric representation of the day of the week - 0 (for Sunday) through 6 (for Saturday)
编辑:啊,所以你想要(只)数字中的文本表示。那么一个简单的地图就足够了:
$dayNames = array( 'Sunday', 'Monday', ..., 'Saturday' );
$day = $dayNames[$row['dow']];https://stackoverflow.com/questions/13013364
复制相似问题