0

I have a date column (trnDate) in an SQL Server Table, which is stored like this in DB


2021-11-29 09:48:05.0000000 +04:00


To read this in Jupyter Notebook, I am using the pymssql package. My code looks like this below

import pymssql
import pandas as pd
import datetime as datetime
conn = pymssql.connect(server, user, password, "HecPoll5")
df = pd.read_sql_query('select * from dbo.v_beeah_data where customerid=379691', conn )
print(df)

The result set however gives me the output where i get hex characters in my dates (marked in bold).

TID----Number----trnDate----LiveMandatorID----Quantity----CustomerID
63221----731----b'\x00$\xd5\xffB\x00\x00\x00\xbc\xae\x00\x00\x...----1----80.0----379691

I have tried adding

parse_dates={"trnDate":"%Y%m%d %H:%M:%S"} & parse_dates=True in read_sql_query & adding charset="UTF-8" parameters in connect as well, nothing have so far worked well.

This is the first time I am using this library, all other columns in the result set works well except the date column. If anyone has previously encountered such issue, kindly help with what I am missing here.

  • the return is a bytes string, so this might help https://stackoverflow.com/questions/6269765/what-does-the-b-character-do-in-front-of-a-string-literal – D.L Jun 22 '22 at 12:05
  • and this to convert the bytes data to a string: https://stackoverflow.com/questions/606191/convert-bytes-to-a-string – D.L Jun 22 '22 at 12:06

0 Answers0