mysql select query where date = … not returning data

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 09:38:23

问题


I've view ReportView

I want to fetch the result having date 10-Feb-2020

I tried

    select * from ReportView where date = "10/02/2020";
    select * from ReportView where date = date_format("10/02/2020","%d/%m/%Y");
    select * from ReportView where date = str_to_date("10/02/2020","%d/%m/%Y");
    select * from ReportView where date_format(date,"%d/%m/%Y") = date_format("10/02/2020","%d/%m/%Y");
    select * from ReportView where str_to_date(date,"%d/%m/%Y") = str_to_date("10/02/2020","%d/%m/%Y");
    select * from ReportView where date = CAST("2020-10-02" AS DATE);
    select * from ReportView where CAST(date AS DATE) = CAST("2020-10-02" AS DATE);

Output is empty :

What actually is happening?


回答1:


You need to use str_to_date() to parse the incoming dates, then date_format() to format them in the way you have it in the table column.

select * from ReportView where date = date_format(str_to_date('10/02/2020',"%d/%m/%Y"), '%d-%m-%Y');


来源:https://stackoverflow.com/questions/60158392/mysql-select-query-where-date-not-returning-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!