设想
UDPATE
请忽略评论部分。在考虑了替代方案后,我想出了这个:
假设我有
$date = '2012-10-03 13:00:00'
时间间隔范围为
2012-10-03 12:00:00 to 2012-10-03 14:00:00
现在$date
落在上述时间范围之间。关于如何将日期时间与日期时间范围进行比较的任何想法?我遇到过比较日期或时间但不能同时比较两者的函数。非常感谢任何帮助。
/*I'm building a school timetable and want to make sure that a room cannot be assigned to two different periods if it is already occupied. I have datetime values of **`2012-10-03 13:00:00`** (the start time of a period. Let's call it **abc** for reference) and **`2012-10-03 13:30:00`** (the end time of a period. Let's call it **xyz** for reference).
My database table contains columns for room number assigned for a period and the start and end time of that period. Something like this:
room_no | start_time | end_time
5 2012-10-03 13:00:00 2012-10-03 14:30:00
This means for October 3, 2012 room 5 is occupied between 1pm and 2:30pm. So the datetime values that I have (abc & xyz) will have to be assigned to a room other than 5.
I'm at a loss of ideas on how to go about validating this scenario, i.e. make sure that the period with time interval between abc & xyz cannot be assigned room number 5.
Any help would be appreciated. Thanks in advance
PS : I'm not asking for code. I'm looking for ideas on how to proceed with the issue at hand. Also, is there a way a query can be build to return a row if `abc` or `xyz` lie between `start_time` and `end_time` as that would be great and reduce a lot of workload. I could simply use the number of rows returned to validate (if greater than 0, then get the room number and exclude it from the result)*/