2013-07-09 40 views
0

我得到一個時間從MySQL中的格式:HH:MM:SS 我需要它比較當前時間和它不工作時間比較不工作PHP

$result = mysql_query('SELECT * FROM events WHERE clubID = "'.$clubID.'" ORDER BY date ASC, TIME(startTime) ASC'); 

while ($row = mysql_fetch_assoc($result)) { 

    $originaltime = $row['endTime']; 
    $time = new DateTime($originaltime); 

    if($time < time()) 
     mysql_query('UPDATE events SET passed="1" WHERE eventID = "'.$row['eventID'].'"'); 

} 

我想要的如果發生語句如果當前時間已經過去$時間(從MySQL)

+2

您與時間戳比較的對象... –

+0

你能做到這一點有一個更新查詢,沒有PHP – 2013-07-09 00:44:26

回答

3

嘗試轉換

new DateTime($originaltime) 

自Unix紀元(1970年1月1日00:00:00到INT(以秒GMT)),所以解決方案HOULD是:

if ($time->format('U') < time()) 
+0

謝謝你這麼多,你是一個LIFESAVER – nshah

+1

@nshah甚至['$ time-> getTimestamp()'](http://www.php.net/manual/en/datetime.gettimestamp.php)作爲DateTime :: format()返回一個可能需要轉換爲整數的字符串。但是'DateTime :: getTimestamp()'返回一個int。 – vascowhite