这看起来像复杂的代码,但我相信这是您所需要的。
<?php
$startDate='2010-01-29';
$endDate='2013-12-30';
$startDateSplit = explode("-",$startDate);
$endDateSplit = explode("-",$endDate);
$starTime = mktime(0, 0, 0, $startDateSplit[1], $startDateSplit[2], $startDateSplit[0]);
$numDaysStart = $startDateSplit[2];
$passThroughDelta = false;
$endTime = mktime(0, 0, 0, $endDateSplit[1], $endDateSplit[2], $endDateSplit[0]);
while ($starTime <= $endTime)
{
$startDate = date('Y-m-d', $starTime);
echo $startDate . "\n";
$startDateSplit = explode("-",$startDate);
$numDays = cal_days_in_month(CAL_GREGORIAN, $startDateSplit[1],$startDateSplit[0]);
echo $numDays . "\n";
if($startDateSplit[1] == 12) {
$startDateSplit[1] = 0;
$startDateSplit[0]++;
}
if($numDaysStart > cal_days_in_month(CAL_GREGORIAN, $startDateSplit[1]+1,$startDateSplit[0])) {
$delta = $numDaysStart - cal_days_in_month(CAL_GREGORIAN, $startDateSplit[1]+1,$startDateSplit[0]);
$numDays = $numDays - $delta;
$passThroughDelta = true;
}
else if ($passThroughDelta) {
$numDays = $numDays + $delta;
$passThroughDelta = false;
}
$starTime = mktime(0, 0, 0, $startDateSplit[1], $startDateSplit[2]+$numDays, $startDateSplit[0]);
}