【发布时间】:2016-05-24 10:43:34
【问题描述】:
我试试这个
<?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;
}
?>
这将返回空白数组。但在两个日期之间2016-07-17 是星期日。
我的输出为2016-07-17
我推荐这个here 但是在这个链接中返回输出为 no of sunday not date。
【问题讨论】:
-
所以你想得到星期天的月份吗?
-
试试这个可能对你有帮助。 stackoverflow.com/questions/1074086/…
-
是的,我得到两个日期之间的所有星期天
标签: php