2014-01-29 103 views
-1

我無法轉換的時間日期時間這個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 
+0

什麼樣的數據類型是datetime和olddate? – silly

回答

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

+0

啊我沒有注意到它,當你發佈,但錯誤是,我有%h時,它應該是24小時%H – user3248308