Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 962
The Other Guy Avatar asked Dec 20 '22 03:12

The Other Guy


2 Answers

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))
like image 69
coleifer Avatar answered Dec 30 '22 17:12

coleifer


You can use peewee's SQL function support:

from peewee import fn

game.select().where(game.created_at == fn.now())
like image 45
pushinginertia Avatar answered Dec 30 '22 17:12

pushinginertia