我们知道在shell中怎么输出一个时间段的所有日期
那么在php中应该如何实现呢
直接上代码
cat date.php
<?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;
}
$list = getDateFromRange('2020-10-01','2020-10-31');
print_r($list);
?>
如何执行
php date.php
如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术
转载请注明:php输出一个时间段的所有日期 出自老鄢博客 | 欢迎分享