0

I'm trying to create a script based on a datepicker in Python and Tkinter.
I can pick a date, start and end date, convert it to unix timestamp, but when I query a sqlite3 database, the response is:

File "/home/frits/Documents/python_datetime/cal.py", line 46, in <module>
c.execute('SELECT * from RecordOne where ct = ?' % unix_timea, (unix_timeb,))
TypeError: not all arguments converted during string formatting

I thought bij converting the unix_time variables to integers solves the problem, but no.
I don't see the error.. Can anyone point out my mistake?
My terrible bad code is:

import datetime
from datetime import timedelta
import time
import sqlite3

def get_date():
    import tkinter as tk
    from tkinter import ttk
    from tkcalendar import Calendar, DateEntry

def cal_done():
    top.withdraw()
    root.quit()

root = tk.Tk()
root.withdraw() # keep the root window from appearing

top = tk.Toplevel(root)

cal = Calendar(top,
               font="Arial 14", selectmode='day',
               cursor="hand1")
cal.pack(fill="both", expand=True)
ttk.Button(top, text="ok", command=cal_done).pack()

selected_date = None
root.mainloop()
return cal.selection_get()

selection = get_date()
dt = selection

start = dt - timedelta(days=dt.weekday())
unix_time = time.mktime(start.timetuple())
unix_timea= int(unix_time)
print(unix_timea)

end = start + timedelta(days=6)
unix_time1 = time.mktime(end.timetuple())
unix_timeb = int(unix_time1)
print(unix_timeb)

conn = sqlite3.connect('monitor.db')
c = conn.cursor()

c.execute('SELECT * from RecordOne where ct = ?' % unix_timea, (unix_timeb,))
test = c.fetchall()
for row in test:
    print(row)

.

fritsimeel
  • 25
  • 6
  • What do you want to do with this expression `'SELECT * from RecordOne where ct = ?' % unix_timea`? Based on your code, `unix_timeb` is used to substitute `?` in the SELECT statement. – acw1668 Jun 13 '22 at 15:52
  • The idea is that there is a startdate and endate and that the query shows those results. The sqlite3 database has records with unix timestamps as integers. thanks for replying. – fritsimeel Jun 13 '22 at 16:08
  • Take a look at this [question](https://stackoverflow.com/questions/29971762/sqlite-database-select-the-data-between-two-dates). – acw1668 Jun 13 '22 at 16:15

0 Answers0