32 小时前 不包括周末 php
所以我有一个脚本可以对 32、48 和 72 小时前进行多次检查。 基本上我会检查数据库中至少 x 小时前的条目。
现在效果很好:
$date = date('Y-m-d H:i:s',strtotime('-32 hours'));
$q = "SELECT * FROM `table` WHERE `date` <= '".$date."'";
现在我希望排除周末。我知道您可以在 strtotime
中使用 weekdays
来获得此效果,但这在几个小时内不起作用。
48 小时很容易,因为我可以简单地执行以下操作:
echo date('Y-m-d H:i:s',
strtotime(date("Y-m-d H:i:s").
" -2 weekdays ".
date('H:i:s')));
72 小时也很容易,因为只有 3 天。然而 32 小时会带来问题,因为它是 ±1.3 天。
总之,如何获取 32 小时前(不包括周末)的日期时间。
So I have a script that does multiple checks for 32, 48 and 72 hours ago.
Basically I check my database for entries that are at least x hours old.
Now this works fine like this:
$date = date('Y-m-d H:i:s',strtotime('-32 hours'));
$q = "SELECT * FROM `table` WHERE `date` <= '".$date."'";
Now I want this to exclude weekends. I know you can use weekdays
within strtotime
to get this effect however this doesn't work for hours.
For 48 hours it's easy because I can simply do the following:
echo date('Y-m-d H:i:s',
strtotime(date("Y-m-d H:i:s").
" -2 weekdays ".
date('H:i:s')));
For 72 hours it's also easy because it's 3 days. However 32 hours poses a problem because it's ±1.3 days.
In conclusion, how do I get the datetime of 32 hours ago excluding weekends.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
像最初一样使用
strtotime
:然后手动进行周末/工作日计算。
Use
strtotime
as you had initially:Then do the weekend/weekday calculation manually.
我不确定这是否正确或最好的方法,但类似:
I am not sure if this is correct or the best way to do it but something like:
为什么不直接去掉两天,加上半手动16个小时来弥补呢?
Why not just remove two days and add 16 hours semi-manually to make up for it?