MySQL check if two date range overlap with input

前端 未结 4 741
生来不讨喜
生来不讨喜 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:01

    This is an old thread, but use BETWEEN. This is an excerpt from my timeclock, pls modify to your needs...

    $qs = "SELECT COUNT(*) AS `count` FROM `timeclock` WHERE `userid` = :userid 
                    AND (
                        (`timein` BETWEEN :timein AND :timeout OR `timeout` BETWEEN :timein AND :timeout )
                        OR
                        (:timein BETWEEN `timein` AND `timeout` OR :timeout BETWEEN `timein` AND `timeout`)
                        );";
    

提交回复
热议问题