Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在这里看到了很多与“日期”相关的问题,但是,我找不到一个可以计算这个的问题:
我试图找出给定日期字符串的数值。例如:
$date = "2010-09-01";
鉴于上述日期,我怎么能确定这是本月的“第一个”星期三。
我知道:date("l", $date); 会告诉我今天是星期三,但我如何确定是每月的第一个、第二个、第三个或第四个星期三?
date("l", $date);
对此的任何帮助都会很棒!
我认为这会让你得到你想要的:
$i = (int) (($day_of_month + 6) / 7);
其中$day_of_month是从 1 到 31。
$day_of_month
你只需要一点数学。
如果该月的日期 < 8,则它是第一个星期三。或者星期五。或者星期一。或者星期六。因此,如果它在 7 到 15 之间,那么它就是第二个。等等。@konforce 已发布实际公式。