php 获取指定日期段内每一天的日期

function getDateFromRange($startdate, $enddate){
$stimestamp = strtotime($startdate);
$etimestamp = strtotime($enddate);
// 计算日期段内有多少天
$days = ($etimestamp-$stimestamp)/86400+1;
// 保存每天日期
$date = array();
for($i=0; $i<$days; $i++){
$date[] = date('Y-m-d', $stimestamp+(86400*$i));
}
return $date;
}
$d=getDateFromRange('2020-06-29','2020-07-05');
ptint_r($d);
结果是:
Array ( [0] => 2020-06-29 [1] => 2020-06-30 [2] => 2020-07-01 [3] => 2020-07-02 [4] => 2020-07-03 [5] => 2020-07-04 [6] => 2020-07-05 )

posted on 2020-06-29 15:42  阳雪凌空  阅读(971)  评论(0编辑  收藏  举报

导航