I am using pyodbc to extract data from a database table. Now, I would like to limit the query to only contain the records that were added within the last 24 hrs. The information about the time a record was added is contained in the DATE_ADDED
column .
This is what I am trying:
pyodbc.pooling = False
conn_str = (
r'DRIVER={Oracle in OraClient12Home1};'
.....
.....
.....)
conn = pyodbc.connect(conn_str)
curs = conn.cursor()
date_today = datetime.datetime.today()
date_yesterday = date_today - datetime.timedelta(days=1)
sql = f"SELECT PROD_ID, ID, COUNT, DATE_ADDED FROM LZE.APODAT WHERE DATE_ADDED < {date_today} AND DATE_ADDED > {date_yesterday}"
my_df = pd.DataFrame(pd.read_sql(sql, conn))
The error message I get is:
UnicodeDecodeError: 'utf-16-le' codec can't decode bytes in position 218-219: illegal encoding
I'm sure it has to do with the different formatting/data types of the DATE_ADDED
column but I am unsure how to approach this. In the database it looks as follows: 2019-04-24 10:21:05 AM
Any help would be greatly appreciated.