简体   繁体   中英

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.

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.

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'.

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

I think you have wrong sql.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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