为什么while循环中的日期不能正确递增? (见代码评论) 任何想法?我在这个带日期的while循环中做了什么错误?
$d1 = strtotime($row['quote_valid_from']);
$d2 = strtotime($row['quote_valid_until']);
$min_date = min($d1, $d2);
//echo date('Y-m-d', $min_date).'<br>'; //(2012-01-01 - start of contract)
$max_date = max($d1, $d2);
//echo date('Y-m-d', $max_date).'<br>'; //(2014-12-31 end of contract)
$ia = 0; // set counter to 0
$nextdate = ''; // set next invoice date to 0
$prevdate = ''; // set previous invoice date to 0
while ($min_date <= $max_date)
{
$nextdate = date('Y-m-d', strtotime($row['quote_valid_from'] . ' +'.$ia.' MONTHS')); // start at 0 and increment at end of insert statement
$prevdate = date('Y-m-d', strtotime($nextdate . ' -1 MONTHS')); // for the previous invoice date, just decuct one month from the next invoice date
echo $prevdate.'<br>';
echo $nextdate.'<br>';
// Here is the weird thing:
// The latest date I get in my while loop is: 2012-08-01
// Insert happens now.
$ia++; //increment $ia by 1
$min_date = strtotime('+'.$ia.' MONTHS', $min_date); //add a month on to my minumum date for the while
} // end while
感谢 Ĵ
定义“一个月”。 31天? 30? 28? ... 29? –
你使用的是什么版本的PHP? –