Is there a straightforward way to find if a time is between two times? (00:00-23:59) I represent the times by the starting time and an DAY TO SECOND
interval, because I want to account for the interval overlapping midnight.
For instance: I have a time 15:20 and want to find if it is in these intervals:
10:00, interval 06:00 - yes
15:00, interval 01:00 - yes
23:30, interval 20:00 - yes
16:00, interval 05:00 - no
And for time 21:00:
20:00, interval 06:00
The data is stored in a table:
CREATE TABLE Opening_Interval
(
IntervalID INTEGER NOT NULL ,
DayOfWeek INTEGER NOT NULL ,
OpenFrom DATE NOT NULL ,
OpenLength INTERVAL DAY (1) TO SECOND (2) NOT NULL ,
);
First thing that comes to mind is
1) Check if wanted_time > beginning_time
2) If yes, check if wanted_time < beginning_time + interval
But I don't think this would work, because in the last scenario the condition would be
1) 21:00 > 20:00? OK
2) 21:00 < 02:00? FAIL
So what would be the correct way to do this?
Edit: related question: when comparing like this: TO_DATE('14:00', 'HH24:MI') >= OPENFROM
, and OPENFROM is of DATE type, does the comparison ignore everything except hours and minutes ?