mysql between operator with dates

前端 未结 4 1115
栀梦
栀梦 2021-01-15 16:46
select \'2011-02-29\' BETWEEN \'2011-02-01\' AND \'2011-03-03\'‎

this is returning 1. I think between doesn\'t consider leap year.

4条回答
  •  北恋
    北恋 (楼主)
    2021-01-15 17:17

    You're comparing strings ... you have to cast the values (or at least the first one) to DATE

    Use this:

     SELECT DATE('2011-02-29') BETWEEN '2011-02-01' AND '2011-03-03'
    

    This will give you NULL because the date is not real.

     SELECT DATE('2008-02-29') BETWEEN '2008-02-01' AND '2008-03-03'
    

    This will give you 1 (TRUE) because the date is real (leap year)

提交回复
热议问题