How to search in sql for hour/minutes?
-
24-09-2019 - |
Question
I have to search all rows with a filter with specific hour and minute.
Example:
26/05/2009 - 16:00
26/05/2009 - 17:00
10/11/2009 - 09:00
10/11/2009 - 10:00
10/11/2009 - 11:00
10/11/2009 - 12:00
I want all rows with hour/minute "17:00" and "18:00". And the date is optional field.
I don't know how to do this. I'm using "sql anywhere 11".
Solution
select *
from tab
where datepart( hour, date_col ) in (17,18)
and datepart( minute, date_col ) = 0
and datepart( second, date_col ) = 0
OTHER TIPS
Another option is:
select * from tab where convert(time,date_col) in ( '17:00','18:00')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow