Sep-17-2025, 09:33 AM
Hi
I'm using the code below to import from an ODBC database. At the moment I'm hard-coding the dates, for example, I can't work out the syntax to replace the second date with datetime.today().strftime('%Y-%m-%d'). Could anyone offer a suggestion where I'm going wrong.
columns_to_select = ['STOCK_CODE, RECORD_CREATE_DATE, TRAN_NUMBER, COST_PRICE, QUANTITY, TYPE']
# Construct the query
sql_query = f"""
SELECT {', '.join(columns_to_select)}
FROM STOCK_TRAN
WHERE RECORD_CREATE_DATE >= '2023-01-31' AND RECORD_CREATE_DATE < '2025-09-17'
"""
# Execute the query
df = pd.read_sql_query(sql_query, conn)
Thanks
I'm using the code below to import from an ODBC database. At the moment I'm hard-coding the dates, for example, I can't work out the syntax to replace the second date with datetime.today().strftime('%Y-%m-%d'). Could anyone offer a suggestion where I'm going wrong.
columns_to_select = ['STOCK_CODE, RECORD_CREATE_DATE, TRAN_NUMBER, COST_PRICE, QUANTITY, TYPE']
# Construct the query
sql_query = f"""
SELECT {', '.join(columns_to_select)}
FROM STOCK_TRAN
WHERE RECORD_CREATE_DATE >= '2023-01-31' AND RECORD_CREATE_DATE < '2025-09-17'
"""
# Execute the query
df = pd.read_sql_query(sql_query, conn)
Thanks
