如何从数据库中的已存储时间中减去时间
$v_id = mysqli_query($mysqli," SELECT V_ID FROM van WHERE (v_starttime -'$row4') BETWEEN -1030 AND 2040");
答案 0 :(得分:1)
你应该使用TO_DAYS天数,然后从日期减去
$v_id = mysqli_query($mysqli," SELECT V_ID FROM van WHERE (TO_DAYS(DATE(v_starttime)) -TO_DAYS(DATE('$row4'))) BETWEEN -1030 AND 2040");
其中$ row4也是日期。
您可以使用TO_SECONDS执行此操作并执行60 * 60分区
$v_id = mysqli_query($mysqli," SELECT V_ID FROM van WHERE ((TO_SECONDS(v_starttime) -TO_SECONDS('$row4'))/3600) BETWEEN -1030 AND 2040");
答案 1 :(得分:1)
我有一个想法,这可能是错误的方式,但给出正确的结果是完成它
$van_id = array();
$i=0;
while(empty($rows[$i]) === false){
$v_id = mysqli_query($mysqli," SELECT V_ID ,v_starttime FROM van WHERE r_id = '$rows[$i]'");
$f=0;
while($rowb = $v_id->fetch_assoc()) {
$ty= (strtotime($rowb['v_starttime']) - strtotime($row4))/60;
//这是它或我是怎么做的!!
if($ty>-40 && $ty<40) {
$van_id[$f]= $rowb['V_ID'];
mysqli_query($mysqli,"UPDATE `emp` SET `V_ID` = '$van_id[$f]' WHERE `username` = 'bla'");
}
$f++;
}
$i++;
}
我只是从数据库中提取时间转换它然后减去已提取的时间也转换它然后只需将整数除以60得到分钟然后存储它$ van_id数组