<?php
/**
* 获取指定日期段内每一天的日期
* @param Date $startdate 开始日期
* @param Date $enddate 结束日期
* @return Array
*/
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;
}
// demo
$date = getDateFromRange('2016-02-25','2016-03-05');
print_r($date);
Last modification:February 28, 2022
© Allow specification reprint
Comment here is closed