This question can be thought as a follow up for Python and MSSQL: Filtering techniques while retrieving data from SQL
Basically, I want to retrieve data from SQL Server for a date range set dynamically.
As of now, I am able to run the following code successfully.
import pyodbc
import pandas as pd
cnxn = pyodbc.connect('DRIVER={SQL Server Native Client 11.0};SERVER=server IP address;DATABASE=dbname;UID=userid;PWD=psswd')
query_pf = "select * from PowerFactor where DeviceTimeStamp between '2019-03-07' and '2019-03-07' "
df_pf = pd.read_sql_query(query_pf,cnxn)
I want the two dates to be set as dynamic. Something like today 00:00:45 and today -1 23:59:59
How it can be done? Perhaps I need to pass a param in dict format?