2011-09-22 63 views
0

我試圖分析我的MYSQL日期的格式YMD H:I:S和得到錯誤:

//theses lines ok 
echo $now = date('Y-m-d H:i:s',$_SERVER['REQUEST_TIME'])."<br/>"; 
echo $nowday = date('d',$_SERVER['REQUEST_TIME'])."<br/>"; 
echo $nowmonth = date('m',$_SERVER['REQUEST_TIME'])."<br/>"; 


echo $userdate = $usr_profile->getCreatedAt()."<br/>"; 
echo $newdate = date('Y-m-d H:i:s',$userdate)."<br/>"; //line 67 error 
echo $usermonth = date('m',$newdate)."<br/>"; //line 68 error 



2011-01-21 08:44:07 

注意:在遇到非合式數值的/ home/helloises/github_mira/rainbow_code/phoenix/plugins/rainbowCodePlugin/modules/profile/templates/homeSuccess.php on line 67 1970-01-01 00:33:31 注意:在/ home/helloises/github_mira/rainbow_code/phoenix /插件/ rainbowCodePlugin /模塊/配置文件/模板/ homeSuccess.php在線68 01

我不明白...我需要檢查兩個日期(現在和userdate)之間的差異是否大於24小時 我嘗試了幾個東西像strtotime,create_date,format_date,DateTime(),但現在利用 請幫忙?

謝謝

回答

1

你可以嘗試在strtotime包裝$newdate

$newdate = date('Y-m-d H:i:s', strtotime($userdate))."<br/>" 
+0

回聲$ newdate =日期( 'Y-M-d H:I:S' 的strtotime($ userdate))。 「
」;給我:1970-01-01 00:00:00這不是我的數據庫字段中的日期??我應該得到:2011-01-21 08:44:07如果我這樣做:echo $ userday = date('d',$ newdate)。「
」;我必須得到21 ..請幫助?謝謝 –

+0

你可以'var_dump($ userdate)'並回發這個函數的整個輸出。 –

+0

$ userdate = $ usr_profile-> getCreatedAt()。「
」; var_dump($ userdate)。「
」;給出:字符串(24)「2011-01-21 08:44:07」 –