PHP 确定每月的星期几
我在这里看到了很多与“日期”相关的问题,但是,我一直无法找到计算此问题的问题:
我正在尝试找出给定日期字符串的数值。例如:
$date = "2010-09-01";
给定上面的日期,我如何才能确定这是该月的“第一个”星期三。
我知道: date("l", $date);
会告诉我今天是星期三,但如何确定它是该月的第一个、第二个、第三个还是第四个星期三?
任何对此的帮助都会很棒!
I've seen lots of "Date" related questions here, however, I haven't been able to find one that calculates this:
I am trying to figure out the numerical value of a given date string. For example:
$date = "2010-09-01";
Given the date above, how might I be able to determine that this is the "1st" Wednesday of the month.
I know that: date("l", $date);
will tell me that it's a Wednesday, but how do I determine if it's the 1st, 2nd, 3rd, or 4th Wednesday of the Month?
Any help on this would be great!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为这可以满足您的需求:
其中
$day_of_month
是从 1 到 31。I think this gets you what you want:
where
$day_of_month
is from 1 to 31.你只需要一点数学知识。
如果该月的某天 < 8,然后是第一个星期三。或者星期五。或者星期一。或者星期六。所以如果它在 7 到 15 之间,那么它就是第二个。等等。 @konforce 已经发布了实际的公式。
You just need a little bit of maths.
If the day of the month is < 8, then it's the first Wednesday. Or Friday. Or Monday. Or Saturday. So if it's between 7 and 15, then it's the second whatever. And so on. @konforce has posted the actual formula.