Adam :
I am trying to convert long date format string (e.g. 1st-June-1999 or 20th-March-2001) to date YYYY-MM-DD using MySql 5.7.
Reading docs tried to use STR_TO_DATE
:
select STR_TO_DATE(dob,'%d-%M-YYYY') from table
However, this returns null
due to the day suffix (e.g. th
).
I could use update query with REPLACE()
to remove the suffix and then STR_TO_DATE
, but is there a better solution?
GMB :
%D
does what you want:
str_to_date(dob, '%D-%M-%Y')