2012-08-31 48 views
0

我在本地wamp設置上運行php 5.3.5。我正在運行一個簡單的代碼。php date_diff問題。得到空白的結果

echo "<br/>DEBUGGING"; 
echo "<br/>==========="; 
echo "<br/>Date: ".$date; 
echo "<br/>Lead Days: ".$lead_days; 
echo "<br/>Date diff: ".var_dump(date_diff((int)$date, (int)$lead_days))." difference"; 

但輸出是:

DEBUGGING 
=========== 
Date: 2012-08-31 
Lead Days: 2012-09-05 

boolean false 


Date diff: difference 

date_diff似乎返回false。我已經嘗試了沒有var_dump和沒有int鑄造,但它總是空白,但它工作,如果我上傳到我的網絡服務器。任何想法這裏有什麼不對?

回答

3

你不能將日期字符串大小寫爲int。

date_diff需要兩個DateTime對象作爲參數,並返回一個DateInterval對象。

$interval = date_diff(new DateTime($date), new DateTime($lead_days)); 
echo "<br/>Date diff: " . $interval->d . " days difference";