Compare only day and month with date field in mysql

前端 未结 4 450
慢半拍i
慢半拍i 2020-11-30 07:16

How to compare only day and month with date field in mysql? For example, I\'ve a date in one table: 2014-07-10

Similarly, another date 2000-07-10<

4条回答
  •  伪装坚强ぢ
    2020-11-30 07:51

    You could use DATE_FORMAT:

    SELECT * FROM `table`
        WHERE DATE_FORMAT(STR_TO_DATE(`field`, '%Y-%m-%d'), '%d-%m') = DATE_FORMAT(STR_TO_DATE('2000-07-10','%Y-%m-%d'), '%d-%m')
    

    also the second WHERE is not valid. Anyway you would want to get all rows not only id=1

提交回复
热议问题