所以我有一个脚本可以对 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 小时前的日期时间,不包括周末。
最佳答案
像最初那样使用 strtotime
:
$time = strtotime('-32 hours');
然后手动计算周末/工作日。
// If the day is Sunday or Saturday subtract a full day.
while (date('w', $time) % 6 == 0) {
$time = strtotime('-1 day', $time);
}
$date = date('Y-m-d H:i:s', $time);
关于php - 32 小时前不包括使用 php 的周末,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8136468/