in reply to Midnight wraparound.
Basically if you get through all the conversion crap, it should look like this:select id, event_time from table order by to_char(sysdate+(to_timestamp(to_char(event_time,'MM/DD/YYYY' +)||' '||to_char(systimestamp,'HH24:MI'), 'MM/DD/YYYY HH24:MI') +1-event_time),'HH24:MI') desc;
Which is basically saying, add a day to wherever you are now. Then subtract the time only portion (event_time) from that, and sort in descending order (largest to smallest). The idea is that anything that is the farthest away from tomorrow at this time, will be the closest thing to today at this time, because the window is 24 hours and your event_time only has a range of 24 hours.select id, event_time from table order by to_char(systimestamp+1-event_time,'HH24:MI') desc;
|
|---|