D
D
Delerium2017-05-09 14:36:06
MySQL
Delerium, 2017-05-09 14:36:06

How to properly pass json to mysql datetime?

there is an api that eventually streams me this json with (sometimes less than a second):
{"data":"someData", "time":"2017-05-09T11:11:59.239549539Z"}
each stream is inserted into mysql:
db .query('INSERT INTO `table_name` SET `data`=?, `time`=?', [jsondata.data, jsondata.time]);
How do I convert this "2017-05-09T11:11:59.239549539Z" into the correct format for insert. But it is necessary that if the requests in the same second differ by date (it was possible to sort)
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
myspace, 2017-05-09
@Delerium

jsondata.time = new Date(jsondata.time)
db.query('INSERT INTO `table_name` SET ?', jsondata);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question