Reputation: 99
I'm using python and sqlite3, and i'm trying to select data from my database, based on input date range.
since = input("Enter date since = ")
dateuntil = input("Enter date until = ")
year, month, day = map(int, since.split('-'))
since = datetime.date(year, month, day)
year, month, day = map(int, dateuntil.split('-'))
dateuntil = datetime.date(year, month, day)
connection, cursor = connect_db()
cursor.execute("select * from dates where myDate BETWEEN ? AND ?;", since, dateuntil)
alldata = cursor.fetchall()
But, it shows "TypeError: function takes at most 2 arguments (3 given)". Any suggestion below would be highly appreciated. Thank you
Upvotes: 1
Views: 772
Reputation: 195
cursor.execute
takes 2 arguments: the query and the query args tuple.
You need to change since, dateuntil
to a 2-element tuple: (since, dateuntil)
:
cursor.execute("select * from dates where myDate BETWEEN ? AND ?;", (since, dateuntil))
Upvotes: 1