MySql和PHP时间重叠

时间:2016-02-15 09:53:39

标签: php mysql

例如,我有以下时间插入:

7 am to 12pm

我数据库中的数据是:

8 am to 9 am ,
11 am to 1 pm ,
5 am to 7 am

我需要在'WHERE'语句中添加'SELECT'语句,以便在返回值时表示当前时间已经为'RESERVED',如果不是则为AVAILABLE ' 1}}

我目前的代码是

select eventDate,timestart,timeend from eventcalendar where eventDate='$eventdate' and
 ((Cast('$timestart' as time) > timestart  and Cast('$timestart' as time) < timeend) or  
 (Cast('$timeend' as time) > timestart  and Cast('$timeend' as time) < timeend)) or 
((Cast('$timestart' as time) between timestart and timeend) or ((Cast('$timeend' as time) between timestart and timeend)))

1 个答案:

答案 0 :(得分:0)

我终于通过添加和反转给定的

来解决它
"select eventDate,timestart,timeend from eventcalendar where eventDate='$eventdate' and 
 ((Cast('$timestart' as time) > timestart  and Cast('$timestart' as time) < timeend) or  
 (Cast('$timeend' as time) > timestart  and Cast('$timeend' as time) < timeend)) or 

  (timestart >  Cast('$timestart' as time) and timestart < Cast('$timeend' as time))  or
(timeend >  Cast('$timestart' as time) and timeend < Cast('$timeend' as time))   "