日期区间
<?php $begin = new DateTime( '2012-08-01' ); $end = new DateTime( '2012-08-08' ); $end = $end->modify( '+1 day' ); $interval = new DateInterval('P1D'); $daterange = new DatePeriod($begin, $interval ,$end); foreach($daterange as $date){ echo $date->format("Y-m-d") . "<br>"; } ?>
Thinkphp方式
<?php $interval = new \DateInterval('P1D'); $starttime = new \DateTime($start_time); $endtime = new \DateTime($end_time); $endtimerel = $endtime->modify('+1 day'); $dateranges = new \DatePeriod($starttime, $interval, $endtimerel); foreach ($dateranges as $datev) { $daylang = $datev->format('Y-m-d'); echo $daylang; } ?>
编程改变生活
posted on 2017-11-25 20:27 coding-farmer 阅读(264) 评论(0) 编辑 收藏 举报