我有一個函數來計算兩個日期之間的差異。日期差異在php
function getDateDifference($to, $from, $in) {
$diff = abs($to - $from);
$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));
if ($in == "days") {
return $days;
} else if ($in == "months") {
return $months;
} else if ($in == "years") {
return $years;
}
}
有關參數我第一次兩個日期轉換成秒這樣,
checkin = '2012-07-26';
checkout = '2012-07-27';
check_in_date = strtotime(checkin);
check_out_date = strtotime(checkout);
即時得到正確的區別,當談到差不到一個月。但是,如果差異超過一個月,我總是把差異作爲1.有人能告訴我問題是。
有很多你選中此http://stackoverflow.com/questions/676824/how-to-calculate-the-difference-between-two-dates-using-php – 2012-07-26 10:04:21