2012-01-05 148 views
0

我很困惑在哪裏尋找解決方案。我最初使用DateTime :: diff來解決這個問題,但是,這次服務器的PHP版本爲< 5.3。時間的差異

我計算時間差,

$beyond= $_POST['beyond']; // 2012-01-07 
$here= $_POST['here']; //2012-01-14 
$interval = abs(strtotime($beyond) - strtotime($here)); 

的這個輸出是,我要輸出到這個字符串的+7的值或者幹​​脆7.

感謝。

+0

我想你會發現這個問題很有用:http://stackoverflow.com/questions/2690504/php-producing-relative-date-time-from-timestamps – Jonathan 2012-01-05 17:35:34

+1

嘿,如果你使用我的代碼,請看我的編輯!我把'86000'改成了'86400',這是一天中正確的秒數。 – 2012-01-06 11:30:08

回答

1

,我認爲這可以幫助你:

$beyond= "2012-01-07"; 
$here= "2012-01-15"; 
$interval = abs(strtotime($here) - strtotime($beyond)); 

$interval/= 86400; 

echo round($interval); 

剛剛得到了一天的時間,除(86400個secunds一天)。

+1

可能存在+/- 1小時的問題。 – RiaD 2012-01-05 17:49:06

+0

@RiaD,但有一個修復? – 2012-01-05 17:51:19

+1

圓形而不是地板可能會有所幫助 – RiaD 2012-01-05 17:53:39