Home:ALL Converter>Converting datetime sql server type to JSON python

Converting datetime sql server type to JSON python

Ask Time:2020-04-17T21:55:45         Author:Nir Elbaz

Json Formatter

I developed an API to my sql server azure database,deployed with azure functions.

I have Python code that is using request to call the API which is also in Python.

I have one issue that i am not able to resolve ,

Description of my objective : I am getting 10K records from one table with the API and want to insert them into a new table , since the request is HTTPS i am converting the query result into json with json.dumps .

The problem: In most of my database tables i have a field that is populated with sysdatetime() sql function. When trying to preform the insert command(I am using executemany) i am getting: 'String data, right truncation: length 52 buffer 46'

Example: I have 10K list of list the in each list i have item in the following format '2020-04-15 05:02:10.023000'. from the other hand: '2020-04-14 00:00:00' is not throwing errors.

The solution i am looking: To be able to convert to Json in my code(I prefer not to change the API code) with out need to iterate over all records one by one.

Any ideas?

Thanks,

Nir

Author:Nir Elbaz,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/61273371/converting-datetime-sql-server-type-to-json-python
yy