2012-08-13 142 views
-2

我需要檢查日期+ 1個月的DB與正確的日期。我嘗試:UNIX_TIMESTAMP不正確的結果

$todayDate = date("Y-m-d"); 
$dateOneMonthAdded = strtotime(date("Y-m-d", strtotime($todayDate)) . "+1 month"); 

$result = mysql_query('SELECT UNIX_TIMESTAMP("date") AS date FROM followform WHERE id = "28"') or die(mysql_error()); 
$date = mysql_fetch_assoc($result); 

if ($dateOneMonthAdded == $date['date']) echo 'nice'; 

但是$日期[ '日期'] == 0

如果我使用 - mysql_query('SELECT date FROM followform WHERE id = "28"')

$date['date'] == 2012-08-13 

哪裏是我的錯?

+0

@MichaelYounani:看[這裏](http://meta.stackexchange.com/a/110645/172011) – 2012-08-13 15:14:30

回答

4

UNIX_TIMESTAMP("date")應該是UNIX_TIMESTAMP(date)。用那裏的引號,它試圖將字符串「date」轉換爲時間戳。

+0

不錯。但現在$ date ['date'] == 1344578400.和1344578400!= $ dateOneMonthAdded – Nick 2012-08-13 15:21:48

+0

那麼'$ dateOneMonthAdded'是什麼?你確定它是正確的嗎?你確定記錄28是比當前日期(第二個)提前一個月嗎? – jli 2012-08-13 15:24:10

+0

對不起。我的錯。是工作! – Nick 2012-08-13 15:35:10

2

從查詢中刪除從unix_timestamp功能的雙引號"功能。它應該是:

SELECT UNIX_TIMESTAMP(date) AS date FROM followform WHERE id = "28"