I have a table with dates, some of which have this format 31-DEC-2010
while others have this format 2011-01-13
.
I am trying to get all them having the date format, using the str_to_date()
function, but it fails since it can not convert 2011-01-13 (some of the dates are already in the correct format because I ran this command previously but then I added more data)
UPDATE `Table1` SET `date` = str_to_date( `date`, '%d-%M-%Y' );
Is there some way to run this command only on the rows that have this format?
You should think of changing the data type to
date
and store dates in mysql fomat that will make life simple.Now if you do a str_to_date() with a date format and the input is not in the format then it will return null.
So you can do the trick as
UPDATE
This might fall into a warning as
So the other approach is to use
regex
for the update