MySQL compare DATE string with string from DATETIME field

前端 未结 7 654
闹比i
闹比i 2020-11-29 19:55

I have a question: Is it possible to select from a MySQL database by comparing one DATE string \"2010-04-29\" against strings that are stored as DATETIME (2010-04-29 10:00)?

7条回答
  •  一向
    一向 (楼主)
    2020-11-29 20:40

    You can cast the DATETIME field into DATE as:

    SELECT * FROM `calendar` WHERE CAST(startTime AS DATE) = '2010-04-29'
    

    This is very much efficient.

提交回复
热议问题