I have had mysql query to check any particular reservations existing in database . These conditions are working in patient doctor reservation system
Background :
I have system which checks available time slots .And displays next available time . As per system my next available time is 9:15 AM to 10:45 AM . But there in admin side I’ve set a reservation 10:00AM to 10:30,this is set by admin . So I need to show users a message “There is a booking between the requested time 9:15 to 10:45 .You can’t use the entire time” .
I wrote a query but its not working ,its not giving any results
SELECT *
FROM reservation
WHERE facility_id = '24'
AND (
'2012-03-02 09:15:00' >= CONCAT( reservation_date, ' ', reservation_time, ':00' )
AND '2012-03-02 09:15:00' <= CONCAT( reservation_date, ' ', reservation_end_time, ':00' )
)
AND '2012-03-02 10:45:00' >= ( CONCAT( reservation_date, ' ', reservation_time, ':00' )
AND '2012-03-02 10:45:00' <= CONCAT( reservation_date, ' ', reservation_end_time, ':00' ) )
Anyone can tell me any problem with my query .
It shouldn’t work becouse you are comparing strings not datetime values. use for example
Date_FORMAT()like this:BTW: This is a bad design, it would be be easier if
reservation_dateis adatetime, then you can directly compare the two values usingBETWEENor without all these casting.