Monday 3 September 2018

I convert Date in the mysql query does not work with str_to_date?

I am converting Date in Mysql query. It's saved in varchar in database in this format 10-January-2015. I am converting it to year-month-date 2015-01-10. I have used str_to_date(myfield, '%d-%M-%Y'), and date_format(myfield, '%d-%M-%Y'), but it shows no rows.

The query I'm writing shows no rows yet it works when I give exact date in string.
SELECT * FROM table where str_to_date(date, '%d-%M-%Y') = '20-June-2015';


use mysql Date_Format
Date_Format(date, '%d-%M-%Y')

use query like taht:-
SELECT * FROM table where Date_Format(date, '%d-%M-%Y') = '20-June-2015';

Or use str_to_date like that :-
SELECT * FROM table where date= str_to_date('20-June-2015', '%d-%M-%Y')

0 comments:

Post a Comment