mySQL:从“yyyy-mm-ddThh-mm-ss.sssZ”转换为“yyyy-mm-dd hh-mm-ss”

时间:2015-08-07 08:20:36

标签: mysql

我想用mySQL将我的数据从“yyyy-mm-ddThh-mm-ss.sssZ”转换为“yyyy-mm-dd hh-mm-ss”。

我尝试使用convert_tz:

@"hello"

并使用演员:

mysql> SELECT CONVERT_TZ('2014-09-29T14:00:00.99Z','+00:00','+00:00');
+---------------------------------------------------------+
| convert_tz('2014-09-29T14:00:00.99Z','+00:00','+00:00') |
+---------------------------------------------------------+
| 2014-09-29 14:00:00                                     |
+---------------------------------------------------------+

但每次我收到警告:

mysql> SELECT CONVERT_TZ(CAST('2014-09-29T14:00:00.99Z' 
       AS datetime),'+00:00','+00:00');
+---------------------------------------------------------------------------+
| CONVERT_TZ(CAST('2014-09-29T14:00:00.99Z' AS datetime),'+00:00','+00:00') |
+---------------------------------------------------------------------------+
| 2014-09-29 14:00:00                                                       |
+---------------------------------------------------------------------------+

如何在没有警告的情况下获得mysql> show warnings; Level | Code | Message Warning | 1292 | Truncated incorrect datetime value: '2014-09-29T14:00:00.99Z'

2 个答案:

答案 0 :(得分:3)

我终于找到了它!

https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_str-to-date

mysql> SELECT STR_TO_DATE('2015-08-07T09:27:54Z','%Y-%m-%dT%TZ');
+----------------------------------------------------+
| STR_TO_DATE('2015-08-07T09:27:54Z','%Y-%m-%dT%TZ') |
+----------------------------------------------------+
| 2015-08-07 09:27:54                                |
+----------------------------------------------------+
1 row in set (0.00 sec)

答案 1 :(得分:0)

请尝试SELECT DATE_FORMAT('2014-09-29T14:00:00.99Z', '%Y-%m-%d %T');