Link to home
Start Free TrialLog in
Avatar of fasse
fasse

asked on

Format dates for use with Progress Database from Pyhton

I run an order import routine and I am modify a python script to check that they are in the system once it is done importing.  My code lookeds like this.  I am trying to learn the pieces of putting this together.  If I take the date part out I can get it to return orders to the screen so I know it is a formatting issue on the date that is making this not work correctly. I am using the pyodbc library.

d = datetime.datetime(2017, 5, 3)
print (d)
sql = "select OrderNum, POnum, OrderDate from PUB.OrderHed where OrderDate ="+d
cnxn = pyodbc.connect("DRIVER={Progress OpenEdge 10.1b Driver};HostName="+host+";DATABASENAME="+database+";PORTNUMBER="+port+";LogonID="+login+";PASSWORD="+password)
cursor = cnxn.cursor()
cursor.execute(sql)
rows = cursor.fetchall()
for row in rows:
    print(row.OrderNum, row.PONum, row.OrderDate)

this is what it returns.

    sql = "select OrderNum, POnum, OrderDate from PUB.OrderHed where OrderDate ="+d

TypeError: must be str, not datetime.datetime

I have tried everything I can find to convert to a string but then I am not sure that if it is a string format trying to pull a datetime format from progress if that is the error.

Any help would be greatly apppreciated.
ASKER CERTIFIED SOLUTION
Avatar of Zberteoc
Zberteoc
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial