1

I have a date field (var) holding date information in format of "mm-dd-yy" e.g 07-01-12. I need to change it to date format. I tried the following but doesn work. I get an Syntax error.

mysql_query("UPDATE `table-name` 
             SET `column-name` = STR_TO_DATE(`column-name`, '%m-%d-%y')")
4

1 に答える 1

2

If the datatype of column-name is DATETIME or DATE, you cannot change its format. Leave it as is.

Just format the values during SELECT statements.

Or if you really want to have that kind of format, create a new column (but don't delete the old one containing the dates) which holds that kind of format. Of course the datatype should be VARCHAR.

于 2013-01-23T01:49:18.720 に答える