我需要一种在PHP中添加"工作日"的方法.例如,星期五12/5 + 3个工作日= 12月12日星期三.
至少我需要代码来理解周末,但理想情况下它也应该考虑美国联邦假期.我敢肯定,如果有必要,我可以通过蛮力提出解决方案,但我希望那里有更优雅的方法.任何人?
谢谢.
我试试这个
<?php
$startdate = '2016-07-15';
$enddate = '2016-07-17';
$sundays = [];
$startweek=date("W",strtotime($startdate));
$endweek=date("W",strtotime($enddate));
$year=date("Y",strtotime($startdate));
for($i=$startweek;$i<=$endweek;$i++) {
$result=$this->getWeek($i,$year);
if($result>$startdate && $result<$enddate) {
$sundays[] = $result;
}
}
print_r($sundays);
public function getWeek($week, $year)
{
$dto = new \DateTime();
$result = $dto->setISODate($year, $week, 0)->format('Y-m-d');
return $result;
}
?>
Run Code Online (Sandbox Code Playgroud)
这个返回空白数组.但在两个日期之间2016-07-17是星期天.
我输出为 2016-07-17
我在这里提到这个 但是在这个链接中返回输出为星期日没有日期.