此函數返回兩個日期之間的日期數組。檢查兩個日期之間的日期錯誤,無知
現在,它的工作完全正常,除了一些未知的原因,如果我把它的11月份或3月份作爲參數,我得到的數組少一天。其他幾個月工作完全正常。我絕對無能爲力。
function getListofDatesInRange2($fromDate, $toDate)
{
$fromDate = str_replace("-","/", $fromDate);
$toDate = str_replace("-","/", $toDate);
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
for ($currentDateTS = $fromDateTS; $currentDateTS <= $toDateTS; $currentDateTS += (60 * 60 * 24)) {
$currentDateStr = date("m-d-Y",$currentDateTS);
$dateMonthYearArr[] = $currentDateStr;
}
return $dateMonthYearArr;
}
我重新編寫了它,while循環解決了我的問題。 (雖然我不知道這個問題是擺在首位)
function getListofDatesInRange2($fromDate, $toDate)
{
$fromDate = str_replace("-","/", $fromDate);
$toDate = str_replace("-","/", $toDate);
$dateMonthYearArr = array();
$fromDateTS = strtotime($fromDate);
$toDateTS = strtotime($toDate);
array_push($dateMonthYearArr, date('m-d-Y', $fromDateTS));
while($fromDateTS < $toDateTS) {
$fromDateTS += 86400;
array_push($dateMonthYearArr, date('m-d-Y', $fromDateTS));
}
return $dateMonthYearArr;
}
可能重複的[如何找到兩個指定日期之間的日期?](http://stackoverflow.com/questions/2736784/how-to-find-the-dates-between-two-specified-date) – Treffynnon 2012-04-19 21:44:00