MySQL check if two date range overlap with input

前端 未结 4 784
生来不讨喜
生来不讨喜 2021-02-04 20:32

I need to check if two dates over lap with another two dates in my database.

My database looks like this

+----+--------------+------------+------------+
         


        
4条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-04 21:08

    I believe the following condition matches every possible overlapping case.

    WHERE
    (
        (ScopeStartDate <= EndDate AND ScopeEndDate >= StartDate)
    
    )
    

    except if you declare illogic timespans (for example, those which end before starting)

提交回复
热议问题