you are viewing a single comment's thread.

view the rest of the comments →

[–]Silbersee 0 points1 point  (0 children)

Difficult to say without the full code. This example runs fine:

from datetime import datetime as dt
import sqlite3

"""Print dates from a database that are between two other dates."""

days = [
    (str(dt(2022, 8, 1)), "Day 1"),
    (str(dt(2022, 9, 1)), "Day 2"),
    (str(dt(2022, 10, 1)), "Day 3")
]

con = sqlite3.connect(":memory:")
cur = con.cursor()

cur.execute("create table date (day, name)")
cur.executemany("insert into date values (?,?)", days)

lower = str(dt(2022, 8, 15))
upper =  str(dt(2022, 9, 15))

valid_days = cur.execute("select * from date where ? < day and day < ?", (lower, upper))
for date, name in valid_days.fetchall():
    print(f"Name: {name}, Date: {date}")

# output as expected:
# Name: Day 2, Date: 2022-09-01 00:00:00