简体   繁体   English

日期时间在mysql和php中进行比较以进行预订会议

[英]date time compare in mysql and php for booking meeting

i need to book meeting room start date and end date are of date+time type in mysql when ever user enters data, values get stored in these format 2013-10-03 14:30:00 to 2013-10-03 16:30:00 (both start and end date) and along with that room number(example:2) is also stored. 当用户输入数据时,我需要预订会议室的开始日期和结束日期为mysql中的日期+时间类型,值以以下格式存储:2013-10-03 14:30:00至2013-10-03 16:30 :00(开始日期和结束日期)以及该房间号(示例:2)也将被存储。

now suppose user has made a new entry again, with 现在假设用户再次输入了一个新条目,

1)same time and and same booking room ( start_date : 2013-10-03 14:30:00 to end_date: 2013-10-03 16:30:00)
2)different time and same booking room (start_date:2013-10-03 13:30:00 to end_date: 2013-10-03 15:30:00)
3)different time and same booking room (start_date:2013-10-03 15:30:00 to end_date: 2013-10-03 18:30:00)

in all above case, it should so me error saying this time is not available as its already booked. 在上述所有情况下,都应该让我出错,因为这次已经预订了,所以无法提供该时间。

what i have done till now is : 我到目前为止所做的是:

SELECT  * FROM    calendar WHERE `Room_no`='2' and (StartTime BETWEEN $start_date AND '$start_date' OR EndTime BETWEEN $start_date AND $end_date)

Thanks in advance.i am new to php and mysql.so if any mistake i have done please let me know. 在此先感谢您。我是php和mysql.so的新手,如果有任何错误,请告诉我。

At first it's very difficult to know what your exact problem is. 首先,很难知道您的确切问题是什么。

Look at the query below. 查看下面的查询。 You are using between query between same variable names $start_date and '$start_date'. 您在相同变量名$ start_date和'$ start_date'之间的查询之间使用。

SELECT * FROM calendar WHERE Room_no ='2' SELECT * FROM calendar WHERE Room_no ='2'
AND (StartTime BETWEEN $start_date AND '$start_date' ) OR (EndTime BETWEEN $start_date AND $end_date) AND(开始时间在$ start_date和'$ start_date'之间 )或(结束时间在$ start_date和$ end_date之间)

I think you have wrong sql. 我认为您的SQL错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM