<?php
function getDateRange($startDate, $endDate) {
$begin = new DateTime($startDate);
$end = new DateTime($endDate);
$returnArray = array();
$currentDate = clone $begin;
$interval = new DateInterval('P1D'); // 1天
$period = new DatePeriod($currentDate, $interval, $end->modify('+1 day'));
foreach ($period as $date) {
$returnArray[] = $date->format("Y-m-d");
}
return $returnArray;
}
// 示例
$startDate = '2023-07-01';
$endDate = '2023-07-10';
$dates = getDateRange($startDate, $endDate);
// 输出结果
foreach ($dates as $date) {
echo $date . "\n";
}
?>
Was this helpful?
0 / 0