MySQL compare DATE string with string from DATETIME field

前端 未结 7 664
闹比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:36

    SELECT * FROM `calendar` WHERE startTime like '2010-04-29%'
    

    You can also use comparison operators on MySQL dates if you want to find something after or before. This is because they are written in such a way (largest value to smallest with leading zeros) that a simple string sort will sort them correctly.

提交回复
热议问题