1

I've view ReportView

enter image description here

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 :

enter image description here

What actually is happening?

8
  • 2
    What column type is date in that ReportView view? Commented Feb 10, 2020 at 21:05
  • What if you try select * from ReportView where date = '10-02-2020' ? Commented Feb 10, 2020 at 21:06
  • 1
    Are you sure that data there is Feb 10th and not Oct 2nd? Commented Feb 10, 2020 at 21:07
  • @TheImpaler '10-2-2020' worked. How can I do it with '10/2/2020'? Date format from datepicker is d/m/Y Commented Feb 10, 2020 at 21:09
  • 1
    it is never a good idea the use SQL keywords as field names. Commented Feb 10, 2020 at 21:12

1 Answer 1

2

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');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.