Inserting date
See original GitHub issueThere 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:
- Created 6 years ago
- Reactions:3
- Comments:12 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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 theZ
character at the end that is throwing it off:Thanks @sidorares . Learned something new (and cool) about doing prepared stmt in cli.