I have a date field (tinytext) holding date information in format of “dd-mm-yy” e.g 07-01-90. Using a mysql query I want to change it to yyyy-mm-dd date format. I tried the code below but nothing happens.
mysql_query("UPDATE Table SET date=STR_TO_DATE('date','%Y,%m,%d')");
You’re using the correct function
STR_TO_DATE(str,format)to achieve the goal, but you’re making two mistakes:formatargument does not match the string expression format. You said it’s indd-mm-yyformat while you passed%Y,%m,%d(comma separated) to theformatargument. The query will return a “incorrect datetime value” error. You should use%d-%m-%Y.So, summarizing:
Additionally, consider switching to the recommended PDO extension in place of old and slowly deprecated
mysqlextension.