MySQL convert between two date format

前端 未结 1 624
我寻月下人不归
我寻月下人不归 2021-01-17 01:38

The user will enter the date in this format : 17-Feb-2017

and the date stored in mysql db is in this format : 2015-02-17 00:00:00

what I tried to do is

相关标签:
1条回答
  • 2021-01-17 02:18

    Convert the input to a date type and the column value too:

    SELECT * FROM insurance where date(in_date) > STR_TO_DATE('17-Feb-2017','%d-%b-%Y')
    

    For more explanation about STR_TO_DATE and DATE function see the mysql documentation. Do not convert both values to string, because you can not compare it after the convertion

    0 讨论(0)
提交回复
热议问题