项目实例
/**
* @param $startdate 开始时间
* @param $enddate 结束时间
*/
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('Ymd', $stimestamp+(86400*$i));
}
return $date;
}
$list = getDateFromRange('20210820','20210910');
echo "<pre>";
print_r($list);
echo "</pre>";
Array
(
[0] => 20210820
[1] => 20210821
[2] => 20210822
[3] => 20210823
[4] => 20210824
[5] => 20210825
[6] => 20210826
[7] => 20210827
[8] => 20210828
[9] => 20210829
[10] => 20210830
[11] => 20210831
[12] => 20210901
[13] => 20210902
[14] => 20210903
[15] => 20210904
[16] => 20210905
[17] => 20210906
[18] => 20210907
[19] => 20210908
[20] => 20210909
[21] => 20210910
)
|