get time slot row from given time in mysql

208 Views Asked by At

I've a table time_slots containing the rows start_time and end_time

data are

id start_time       end_time
1  10:00:00         15:00:00 
2  15:00:00         22:00:00 
3  22:00:00         10:00:00 

Im using the query working fine for top two columns

SELECT * FROM time_slots WHERE '18:00:00' BETWEEN start_time AND end_time

but when i tried to get row from 3rd row, it gives me an empty result.

1

There are 1 best solutions below

0
On

Well,

22:00 hours is more then 10:00. So your where clause executes perfectly.

I understand your problem, but i don't know how to fix it in T-SQL... :)

One fix i can think of is to change the TIME fields into DATETIME; the BETWEEN command cán work with those values