Are there any MySQL functions to get all rows with with a start or end date that fall between a given start and end date?

前端 未结 5 2278
名媛妹妹
名媛妹妹 2020-12-06 12:48

I have a table of events with a recorded start and end time as a MySQL DATETIME object (in the format YYYY-MM-DD HH:MM:SS. I want to find all events that occur

5条回答
  •  隐瞒了意图╮
    2020-12-06 13:22

    SELECT *
    FROM table
    WHERE startdate >= 'starting date' AND startdate < 'ending date'
        OR enddate >= 'starting date' AND enddate < 'ending date'
    

    should work for you.

    Make sure you specify 'starting date' and 'ending date' with the time included.

    '2008-01-01 00:00:00'' AND '2008-01-31 23:59:59'
    

    This will help to avoid errors where dates are the same, but your time falls within the interval by a few hours, minutes, or seconds.

提交回复
热议问题