问题
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