Error log:
{ [Error: Incorrect datetime value: ‘2012-08-24T17:29:11.683Z’ for
column ‘robot _refreshed_at’ at row 1] number: 1292, sqlStateMarker:
‘#’, sqlState: ‘22007’, message: ‘Incorrect datetime value:
\’2012-08-24T17:29:11.683Z\’ for column \’ robot_refreshed_at\’ at row
1′, sql: ‘INSERT INTO users
(id,name,count_moments,count_likes,count_followers,rob
ot_refreshed_at,robot_count_followers) VALUES
(\’1834084\’,\’NNNyingzi\’,\’5\’,\
‘0\’,\’0\’,\’2012-08-24T17:29:11.683Z\’,\’0\’)’, setMaxListeners:
[Function], emit: [Function], addListener: [Function], on: [Function],
once: [Function], removeListener: [Function], removeAllListeners:
[Function], listeners: [Function] }
I use this piece of code in my Node.js
if s instanceof Date
return s.toISOString()
and updated them in database.
The SQL insert expression follows:
INSERT INTO users (id,name,count_moments,count_likes,count_followers,rob ot_refreshed_at,robot_count_followers) VALUES (\'1834084\',\'NNNyingzi\',\'5\',\ '0\',\'0\',\'2012-08-24T17:29:11.683Z\',\'0\')
Am I doing anything wrong? I just copied a table using PHPMyAdmin from a table in server.
Thanks a lot.
As stated in Date and Time Literals:
Your date literal of
'2012-08-24T17:29:11.683Z'does not fit any of these formats; suggest you either—use instead the Node.js Date object’s
toLocaleFormat()method (be sure that the timezone of the MySQL connection matches that of Node.js’s locale):use the Node.js Date object’s
valueOf()method to obtain the time’s value in milliseconds since the UNIX epoch, divide by1000(to get seconds since the UNIX epoch) and pass through MySQL’sFROM_UNIXTIME()function.