我想比较一个以格式09:30:14存储时间的db列与以相同格式存储时间的php变量。我想检查存储在dbcolumn中的时间是否少于2分钟存储的时间php使用mysql。我希望根据此检查退出一些值
$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 :(得分: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')";