SQLite Forum

How do I access urls in a sqlite database using timedelta?
Login
What you have there isn't connecting the variable names in Python with the statement at all. So it's going to look for fields in the table with names of "past_time2" and "past_time". And since SQLite isn't strict (by default) about quoting, then if those fields don't exist it'll take them as string literals instead. Which is why it probably runs without an error, but gives an unexpected answer.

You need to bind the two values to the statement.

c.execute("SELECT adUrl FROM donedeal_listings WHERE timestamp BETWEEN ? AND ?;", (past_time2, past_time))