MySQL - ER_TRUNCATED_WRONG_VALUE:Timestamp列上的日期时间值不正确

时间:2017-06-16 17:51:52

标签: mysql datetime error-handling timestamp

我有一个MYSQL列,定义为TIMESTAMP。

每当我使用javascript new Date()创建一行时,该值都会正常存储而不会出现问题。

但是,当我想更新该值时,在该列上发送相同的new Date(),我收到错误

Error: ER_TRUNCATED_WRONG_VALUE: Incorrect datetime value: '2017-06-16T17:35:34.377Z' for column 'last_access'.

我可以将整个事情作为Datetime进行管理并相应地格式化日期以解决错误,但是我想了解错误发生的原因。

1 个答案:

答案 0 :(得分:0)

MariaDB的日期格式必须为“ YYYY-MM-DD HH:MM:SS”。

如果要使用JS插入日期,请​​尝试创建自己的字符串。

const newDate: Date = new Date();
const dd = newDate.getDate();
const number = newDate.getMonth() + 1; // month start at 0, we have to add 1.
const yyyy = newDate.getUTCFullYear();

const insertString = `${yyyy}-${mm}-${dd}`;