日期区间

<?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编辑  收藏  举报

导航