我只是有一个简单的问题,我正在做一个出租车预订系统。我发现在SQL中在接下来的2小时内选择预订会遇到麻烦。当我选择所有内容时,我不需要显示整个预订,我只想在运行查询后两小时内显示。
$query= "select Booking_No,
Email_Address,
Customer_Name,
Passenger_Name,
Phone_No,
concat(Unit_Number,'/', Street_Number,' ', Street_Name,',', Suburb) as Unit_Number,
Destination_Suburb,
Pickup_Date,
Pickup_Time from Booking1
where status = 'false'
and
(Pickup_Time >= DATE_FORMAT(NOW(), '%h:00:00') and
Pickup_Time <= DATE_FORMAT(NOW(), '%h') + interval 2 hour)";
答案 0 :(得分:0)
使用&#39; BETWEEN&#39; WHERE子句中的子句。
WHERE status = 'false' AND Pickup_Time BETWEEN NOW() AND DATE_ADD(NOW(), INTERVAL 2 HOUR)
NOW()返回日期/时间对象,DATE_ADD()返回日期/时间对象。只要你的Pickup_Time是一个日期/时间对象,这就像一个款待!