我正在会议室预订系统上工作,无法确定会议室是否在设定的时间范围内占用,我在使用当前格式的日期并将DATETIME表中的类型设置为:YYYY-MM-DD HH:II:SS
这是我当前的代码:
//Function to check if a booking exists:
function bookingExist($DateStart, $DateEnd, $RoomNo) {
global $DB;
$sql = "SELECT * FROM bookings WHERE date_start = :dateStart AND date_end = :dateEnd AND room_no = :roomNo";
$Q = $DB->prepare($sql);
$Q->bindParam(':dateStart', $DateStart);
$Q->bindParam(':dateEnd', $DateEnd);
$Q->bindParam(':roomNo', $RoomNo);
$Q->execute();
if ($Q->rowCount()) {
//A record exists...
return true;
} else {
//no record exists
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
有什么办法可以在sql查询中执行此操作?
例如:A室在2016-03-31 15:00:00到2016-03-31 17:30:00之间预订-2016-03-31 17:00:00并且此应该返回1记录,因为有预订