2013-10-22 153 views
0

我想比較存儲時間格式爲09:30:14的db列與存儲時間格式相同的php變量。我想檢查存儲在dbcolumn時間是存儲在PHP運行時間不到2個miutes使用mysql.I希望在此基礎上檢查retireve一些值如何檢查時間是否在給定的時間間隔範圍內

$ordertime_present = 09:32:14; 
$ordertime_before = 09:30:14; 

$sql = "select count(keyid) as key_id_count from key_master where orderdate='$orderdate' 
    and ordertime between '$ordertime_present' and '$ordertime_before'"; 

回答

0
$sql = "select count(keyid) as key_id_count 
     from key_master 
     where orderdate='".$orderdate."' 
     and ordertime between str_to_date('".$ordertime_present."','%H:%i:%s') 
          and str_to_date('".$ordertime_before."','%H:%i:%s')"; 

編輯:既然ordertime_before小於ordertime_present,它應該是第一在比較中:

$sql = "select count(keyid) as key_id_count 
     from key_master 
     where orderdate='".$orderdate."' 
     and ordertime between str_to_date('".$ordertime_before."','%H:%i:%s') 
          and str_to_date('".$ordertime_present."','%H:%i:%s')"; 
相關問題