0

I am trying to create booking system, MySQL table has this row

Room Id   |   Start (DateTime) |  |  Finish(DateTime)
13            2014-10-20 08:30    |  2014-10-20 18:30

And I want to block any entries between these start and finish

eg:
Room id: 13
Start: 2014-10-20 10:30
Finish: 2014-10-20 12:30

To do that I have wrote this MySQL query, is this SQL correct?

SELECT * 
FROM rooms
WHERE room_id='13' 
AND ('2014-10-20 12:30:00' <= start_time OR '2014-10-20 10:30:00'>=finish_time) 

In here I tried to skip between result, please advise me.

Gayan
  • 2,845
  • 7
  • 33
  • 60
  • 2
    have a look at this answer: http://stackoverflow.com/questions/325933/determine-whether-two-date-ranges-overlap – Milen Oct 27 '14 at 10:55

1 Answers1

1

You want to between the start time and finish time means I didn't test it but once can you try this..I hope it works

SELECT * 
FROM rooms
WHERE room_id='13' 
AND ('2014-10-20 12:30:00' >= start_time AND '2014-10-20 10:30:00'<=finish_time) 
Choco
  • 1,054
  • 1
  • 7
  • 20