Comparing date ranges

后端 未结 10 1415
予麋鹿
予麋鹿 2020-11-22 16:10

In MySQL, If I have a list of date ranges (range-start and range-end). e.g.

10/06/1983 to 14/06/1983
15/07/1983 to 16/07/1983
18/07/1983 to 18/07/1983
         


        
10条回答
  •  时光取名叫无心
    2020-11-22 16:16

    Taking your example range of 06/06/1983 to 18/06/1983 and assuming you have columns called start and end for your ranges, you could use a clause like this

    where ('1983-06-06' <= end) and ('1983-06-18' >= start)
    

    i.e. check the start of your test range is before the end of the database range, and that the end of your test range is after or on the start of the database range.

提交回复
热议问题