2016-06-01 97 views
0

我要檢查DB小時分鐘比等於當前的時間和小時小,如何在php中檢查DB小時數和分鐘數小於當前小時數和分鐘數?

例如,

以dB爲單位,$ FROM_TIME = 12.00,$ CURRENT_TIME = 8時10分在這些情況下,用戶不能去商店,因爲從時間是12.00Am。

$ from_time = 12.00Am,$ current_time = 12.10在這種情況下,用戶可以去商店,因爲fromtime是12.00Am,用戶可以在當前小時數大於等於我的數據庫細節之後做任何事情。

$ to_time = 9.00pm $ current_time = 8.20在這種情況下,用戶無法去購物。如何檢查這些在PHP中?

+1

你是如何在數據庫中存儲日期?你有什麼嘗試?如果你谷歌'時間比較mysql',你會得到很多建議 –

回答

0
$from_time = strtotime($from_time_from_DB); 
$to_time = strtotime($to_time_from_DB); 
$current_time = strtotime("now"); 

if( $current_time >= $from_time 
    && $current_time < $to_time ) 
{ 
    //user can go to shop 
} 
else 
{ 
    //user can't go to shop 
} 
+0

也許應該''=''和'<=' –

+0

@ darren-sweeney只在'$ current_time> = $ from_time'也許?在用戶關門之前的最後一分鐘不應該去商店 – Dumkaaa

+0

啊,好的電話 - 在打字的時候衝了出來! –