4

I have a MYSQL column that is defined as TIMESTAMP.

Whenever I create a row with javascript new Date() the value is stored ok without issues.

However when I want to update the value, sending the same new Date() on that column, i get an error

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

I can manage the whole thing as Datetime and format the date accordingly to solve the error, however I want to understand why the error is happening.

htafoya
  • 18,261
  • 11
  • 80
  • 104

1 Answers1

1

The Date must be formatted like "YYYY-MM-DD HH:MM:SS" for MariaDB.

If you want to insert a Date with JS, try to make your own string.

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}`;
Tobi
  • 53
  • 1
  • 9