Trying to create a query using python and mariadb

30 Views Asked by At

Sorry, this may be really easy but I am new at learning code, I am trying to return all

yesterday = ((dt.date.today()-dt.timedelta(days=1)))    
cur.execute("SELECT * FROM iron_condor WHERE open='yes' AND DATE(buy_date)<DATE(?)"(yesterday))

I am getting this back

Traceback (most recent call last):
  File "/home/pi/Documents/openoptions.py", line 86, in <module>
    cur.execute("SELECT * FROM iron_condor WHERE open='yes' AND DATE(buy_date)<DATE(?)"(yesterday))
TypeError: 'str' object is not callable
1

There are 1 best solutions below

0
buran On
yesterday = ((dt.date.today()-dt.timedelta(days=1)))    
cur.execute("SELECT * FROM iron_condor WHERE open='yes' AND DATE(buy_date)<DATE(?)", (yesterday,))

note the 2 commas. You may need to convert yesterday to str.