当我尝试从终端中的 $sudo mysql
>>$use DB
将日期时间插入到我的 MAC 本地 mysql 表中时,出现以下错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '('2015-10-07 13:21:30',5)), convert(datetime('2015-10-07 13:41:30',5)))' at line 1
这是插入内容:
INSERT INTO log VALUES (1,28, convert(datetime('2015-10-07 13:21:30',5)), convert(datetime('2015-10-07 13:41:30',5)));
最佳答案
根据mysql的开发页面(https://dev.mysql.com/doc/refman/5.1/en/datetime.html),mySQL中日期时间的默认格式是'YYYY-MM-DD HH:MM:SS'。在您的情况下,如果您有 DATETIME 或 DATE 列,则无需调用任何转换函数来向其中插入日期时间,只需按原样插入日期: '2015-10-07 13:21:30' 即可应该没问题。
一般来说,插入数据时尽量避免转换,因为这会影响数据库性能,尤其是在您主动使用它的情况下。
关于mysql - mySQL 24 小时制的正确日期时间格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33011315/