Date between 2 other dates, disregarding year

后端 未结 1 611
一个人的身影
一个人的身影 2021-01-24 09:38

I\'m looking for something like the person here was lookin for, only I\'d like to use MySQL. The table below is something you\'d find in my database (simplified).



        
相关标签:
1条回答
  • 2021-01-24 10:18

    You need to distinguish two cases.

    1. When first < last, the dates are in the same year. You can then use between to match dates.

    2. When first > last, it means last is in the next year. In this case, the dates that match are date >= first OR date <= last.

    So your WHERE clause should be:

    WHERE IF(first < last, @date BETWEEN first AND last,
                           @date >= first OR date <= last)
    
    0 讨论(0)
提交回复
热议问题