Home > Software design >  How to get rows between 20.00 and 8.00 in mySQL
How to get rows between 20.00 and 8.00 in mySQL

Time:02-23

I want to get dates between 2 times like this:

SELECT * 
FROM `test` 
WHERE hour(tm) BETWEEN 20 and 8;

columne tm is Time type. In my Test table i have next valuse in tm columne:

10:00:00
08:00:00
15:00:00
20:00:00
21:00:00

Code does not work. Any ideas? Thanks!

CodePudding user response:

You should use a direct comparison with time literals:

SELECT * 
FROM test
WHERE tm < '08:00:00' OR tm >= '20:00:00';

CodePudding user response:

Try:

SELECT * 
FROM `test` 
WHERE hour(tm) >= '20' or  hour(tm) <=  '08';

Result:

 08:00:00
 20:00:00
 21:00:00

Demo

  • Related