Mysql错误转换为日期时间

时间:2014-01-29 10:19:52

标签: mysql

我无法使用此mysql查询转换时间:

UPDATE profiles SET datetime = str_to_date(olddate, '%d/%m/%Y %h:%i:%s');
olddate format is: 1/01/2012 0:00
datetime format is 0000-00-00 00:00:00

我已尝试删除秒,但出现同样的错误:

Incorrect datetime value: '1/01/2012 0:00' for function str_to_date

1 个答案:

答案 0 :(得分:0)

试试这个,它会给MySQL格式化datetime

SELECT STR_TO_DATE('1/01/2012 0:00','%d/%m/%Y %H:%i');
+------------------------------------------------+
| STR_TO_DATE('1/01/2012 0:00','%d/%m/%Y %H:%i') |
+------------------------------------------------+
| 2012-01-01 00:00:00                            |
+------------------------------------------------+
1 row in set (0.00 sec)

查看MySQL STR_TO_DATE