0

Let's say I have the below records what i want to do is select the records based on their time of day independent of month, year or day. In short " select all records between 12:00 and 14:00" and it should return me A and D. How can I do that?

A 2012-10-24 12:00:00
B 2012-13-25 03:00:00
C 2012-12-25 20:00:00
D 2012-16-26 14:00:00
Constantine
  • 763
  • 2
  • 9
  • 19

1 Answers1

1

Try this :

SELECT *
FROM table
WHERE HOUR(date) BETWEEN 12 AND 14

read more about this function here(w3 resource)

If you want based on hour and minute, then you need TIME() function.

syntax : WHERE TIME(datetime) >= '18:00:00'

Prabhat G
  • 2,974
  • 1
  • 22
  • 31