开发者

Can I get a zero-based day of the week with zero representing Sunday without using an if statement or ternary operator?

According t开发者_Python百科o http://php.net/manual/en/function.date.php, the format character 'N' returns the ISO-8601 numeric representation of the day of the week which is 1 - 7 for Monday through Sunday. I was curious if there is something that returns a zero-based numeric representation of the day of the week which is 0 through 6 for Sunday through Saturday. Right now I am using an if statement to change any 7's to 0's but I just wanted to know if there was a shorter way of doing this (not that it's that long, though).


Look a bit farther down th epage. There's the w option for 0(sun)-6(sat)


 n          | n % 7
------------+-------
1 through 6 | Same
7           | 0


Modulus with 7. $date = $date % 7;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜