我设法将以下代码用于“工作日”并排除我的特殊日子,但是:
我提供'7个工作日没有存款闲置',虽然我的商店只在星期日休息。所以我需要我的'工作日'来包括所有星期六的。
$tdate = date("Y-m-d");
$specialdays = ['22-09-2017', '03-10-2017', '14-11-2017', '17-12-2017'];
$i = 7;
$sevenbusinessdays = date('d-m-Y', strtotime($tdate . ' +' . $i . '
Weekday'));
while (in_array($sevenbusinessdays, $specialdays)) {
$i++;
$sevenbusinessdays = date('d-m-Y', strtotime($tdate . ' +' . $i . ' Weekday'));
}
我相信使用上面的代码答案与
有关date('w', strtotime($tdate)) == 6
虽然我不确定如何加入它。我尝试过以下但是它不起作用:
$tdate = date("Y-m-d");
$specialdays = ['22-09-2017', '03-10-2017', '14-11-2017', '17-12-2017'];
$i = 7;
$sevenbusinessdays = date('d-m-Y', strtotime($tdate . ' +' . $i . ' Weekday' . date('w', strtotime($tdate)) == '6'));
while (in_array($sevenbusinessdays, $specialdays)) {
$i++;
$sevenbusinessdays = date('d-m-Y', strtotime($tdate . ' +' . $i . ' Weekday' . date('w', strtotime($tdate)) == '6'));
}
print $sevenbusinessdays;
这完全失败哈哈,任何指导和帮助将不胜感激。我想我很接近,只是没有得到它。
感谢您的帮助,非常感谢。 : - )
答案 0 :(得分:1)
你需要循环,在以下情况下添加天数:
直到您添加了7天
<?php
$tdate = date("Y-m-d");
$specialdays = ['15-09-2017', '20-09-2017', '14-11-2017', '17-12-2017'];
$days = 0;
$i = 0;
while ($days < 7) {
$i++;
$day = strtotime($tdate . ' +' . $i . ' day');
if (date("w", $day) === "0" || in_array(date("d-m-Y", $day), $specialdays)) {
continue;
}
$days++;
}
$sevenbusinessdays = date('d-m-Y', strtotime($tdate . ' +' . $i . ' day'));
echo $sevenbusinessdays;