SQL finding overlapping of times pass midnight (across 2 days)
        Posted  
        
            by janechii
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by janechii
        
        
        
        Published on 2010-05-03T18:25:18Z
        Indexed on 
            2010/05/03
            18:28 UTC
        
        
        Read the original article
        Hit count: 223
        
Hi everyone,
I know there are lots of these types of questions, but i didn't see one that was similar enough to my criteria. So i'd like to ask for your help please. The fields i have are just start and end which are of time types. I cannot involve any specific dates in this. If the time ranges don't go pass midnight across day, i'd just compare two tuples as such:
end1 > start2 AND start1 < end2
(end points touching are not considered overlapped here.)
But when I involve time range that pass (or at) midnight, this obviously doesn't work. For example, given:
 start  |   end
--------+--------
06:00PM | 01:00AM
03:00PM | 09:00PM
Without involving dates, how can i achieve this, please. My assumption is, if end is less than start, then we're involving 2 days.
I'm trying to do this in plain standard SQL, so just a simple and concise logic in the WHERE clause.
Thank you everyone!
© Stack Overflow or respective owner