question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

There must be something on my side but I am somewhat stuck.

I’m inserting data into a table using the following approach:

const p = await getPool(name); // caching the pool because I'm accessing multiple dbs
const insertFbl = 'INSERT INTO fbl SET ?'
const result = p.query(insertFbl, some_object)

some_object has some date fields.

When I run the query I get an error like this (for the sake of testing I did init my date field with new Date()):

Incorrect datetime value: ‘2018-01-21T00:37:07.837Z’ for column ‘feedback_date’ at row 1 at PromisePool.query (/server/node_modules/mysql2/promise.js:344:20) …

On the other hand, if I use some string like moment(somedate).format(‘YYYY-MM-DDThh:mm:ss’), it will insert without any problem.

That’s weird because not only mysql2 is supposed to make the appropriate conversion and moreover I could swear I had already used javascript date variables before.

Any idea?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
dougwilsoncommented, Jan 27, 2018

In your above post, I see the error is saying you’re date looks like '2018-01-21T00:37:07.837Z' which is not a string that MySQL server recognizes as a date. I think it’s the Z character at the end that is throwing it off:

mysql> SELECT CONVERT('2018-01-21T00:37:07.837Z', DATETIME);
+-----------------------------------------------+
| CONVERT('2018-01-21T00:37:07.837Z', DATETIME) |
+-----------------------------------------------+
| 2018-01-21 00:37:07.837000                    |
+-----------------------------------------------+
1 row in set, 1 warning (0.00 sec)

Warning (Code 1292): Truncated incorrect datetime value: '2018-01-21T00:37:07.837Z'
mysql> SELECT CONVERT('2018-01-21T00:37:07.837', DATETIME);
+----------------------------------------------+
| CONVERT('2018-01-21T00:37:07.837', DATETIME) |
+----------------------------------------------+
| 2018-01-21 00:37:07.837000                   |
+----------------------------------------------+
1 row in set (0.00 sec)
0reactions
midnightcodrcommented, Nov 12, 2018

Thanks @sidorares . Learned something new (and cool) about doing prepared stmt in cli.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Insert the date and time a document was created, last printed ...
Click where you want to insert the date or time. · On the Insert tab, in the Text group, click Quick Parts, and...
Read more >
How to Insert Today's Date in Word (with Shortcut)
Inserting the current date using the Date & Time command · Click in the document where you want to insert the date: ·...
Read more >
How to insert the date and time in Microsoft Word and WordPad
Open Microsoft Word. · Place the text cursor where you want to insert the date and time. · Click the Insert tab in...
Read more >
How to Insert an Automatic Date Change in Word
1. Click in the document where you want to insert the date. · 2. Click the “Insert” tab on the command ribbon. ·...
Read more >
Insert Date in Word - CustomGuide
1. Click the Insert tab. 2. Click the Date and Time button. 3. Select a date format.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found