mysql YYYY-MM-DDThh:mm:ss

时间:2010-12-30 13:43:05

标签: mysql datetime

mysql是否正确理解dateTime类型的'YYYY-MM-DDThh:mm:ss'格式? 我有几个日期字段来自xml(类型为xsd:dateTime 'YYYY-MM-DDThh:mm:ss'格式)。然后我需要将这些字段保存到DB(mysql dateTime格式为'YYYY-MM-DD hh:mm:ss')我应该将xml的日期格式转换为mysq日期格式吗?或者我可以将这些字段插入数据库而不进行转换吗?

1 个答案:

答案 0 :(得分:4)

是的,确实如此:

mysql> SELECT CAST('2010-12-30T01:02:03' AS datetime);
+-----------------------------------------+
| CAST('2010-12-30T01:02:03' AS datetime) |
+-----------------------------------------+
| 2010-12-30 01:02:03                     |
+-----------------------------------------+
1 row in set (0.08 sec)

mysql> SELECT CAST('2010-12-30 01:02:03' AS datetime);
+-----------------------------------------+
| CAST('2010-12-30 01:02:03' AS datetime) |
+-----------------------------------------+
| 2010-12-30 01:02:03                     |
+-----------------------------------------+
1 row in set (0.00 sec)