数据库只要比较月和日,年份并不在比较的要求之内的时候发现好多方法都不能解决这个问题。因为mysql自带的时间比较都是从年开始比较。因此我也只能通过mysql自带的MONTH和DAY 方法来获取到需要的月份和年份,在通过case_when的方式来实现。
SELECT * from t_Table where
CASE
WHEN startMonth < MONTH(myDate) then 1=1 //恒真
WHEN startMonth = MONTH(myDate) then DAY(myDate) >= startDay
WHEN startMonth > MONTH(myDate) then 1=2 //恒假
END
AND
CASE
WHEN endMonth< MONTH(myDate) then 1=2
WHEN endMonth= MONTH(myDate) then DAY(myDate) <= endDay
扫描二维码关注公众号,回复:
4596984 查看本文章
WHEN endMonth> MONTH(myDate) then 1=1
END