Search code examples
pythondatetimeormpeewee

Compare DatetimeField with datetime.now()


so i'm using peewee orm for this project ,

i want to compare a date from sqlite database with curent date :

class game(BaseModel):
    stuff= CharField()
    stuff2= CharField()
    created_at = DateField()
s=game.select().where(game.created_at==datetime.now().date())

but i can't get it to work , and i'm just getting None as result.


Solution

  • The easiest way is query a range of dates:

    game.select().where(game.created_at.between(
        datetime.date.today(),
        datetime.date.today() + datetime.timedelta(days=1))