如何在Laravel中查看在$from
和$to
之间的给定日期范围内有多少个星期六或星期日?
答案 0 :(得分:1)
你可以使用普通的PHP这样做:
$start = new DateTime('2016-07-07');
$end = new DateTime('2016-07-27');
$interval = new DateInterval('P1D');
$daterange = new DatePeriod($start, $interval ,$end);
$saturdays = 0;
foreach($daterange as $date){
$days = $date->format('D');
if ($days == 'Sat') {
$saturdays++;
}
}
echo $saturdays;