mysql select query where date = ...不返回数据 [英] mysql select query where date = ... not returning data
本文介绍了mysql select query where date = ...不返回数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我查看过 ReportView
I've view ReportView
我想获取日期为 2020 年 2 月 10 日的结果
I want to fetch the result having date 10-Feb-2020
我试过了
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);
输出为空:
实际发生了什么?
推荐答案
你需要使用 str_to_date()
来解析传入的日期,然后使用 date_format()
来格式化它们以您在表格列中的方式显示.
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');
这篇关于mysql select query where date = ...不返回数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文