シナリオ
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)*/