Start New Discussion within our Databases Community

I need to select data available between 20:00 and 08:00 (8 PM to 8 AM).
How do I achieve this?

The column is of type TIME.

That depends on the actual format you're using. If you're not keeping track of the date, it's simply

select * from mytable where timefield <= '08:00' or timefield >= '20:00'

Ok. Maybe I have not come out clear here.
I have a list of data between diff. time periods (so, there's data between 00:00-08:00,08:00-15:00,20:00-08:00 .. so on and so forth).
I have an input field (say, 2012-01-25 21:00).
Now I wish to retrieve all data with a time window that includes 21:00.

The time periods are in two cols. [FROM_WINDOW;TO_WINDOW].

This is how my table is structured: -

ABC123    1899-12-30 20:00:00    1899-12-30 08:00:00
ABC456    1899-12-30 20:00:00    1899-12-30 08:00:00
ABC000    1899-12-30 08:00:00    1899-12-30 15:00:00

Now if my input is 2012-01-25 21:00, the result-set should return 2 rows.

This article has been dead for over six months. Start a new discussion instead.