林之間的差異試圖返回兩個日期之間的區別,我根據example found on stackoverflowPHP比較兩個日期
我的問題的工作?我得到完全錯誤的結果返回,下面的代碼返回30年,0個月,9天,當它顯然應該只有7天或1周。下面
代碼如下:
date_default_timezone_set('America/Los_Angeles');
$pickupDate = '2016-10-13';
$returnDate = 2016-10-20;
$diff = abs(strtotime($pickupDate) - strtotime($returnDate));
$years = floor($diff/(365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24)/(30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
printf("%d years, %d months, %d days\n", $years, $months, $days);
任何輸入讚賞
使用PHP的內置日期函數,不要做天真小時*天的計算。 – Dai