Make Sqlalchemy Use Date In Filter Using Postgresql

后端 未结 4 1927
广开言路
广开言路 2021-02-05 05:32

I\'m trying to perform the following query in Sqlalchemy.

Select * from \"Mytable\" where Date(date_time_field) = \"2011-08-16\";

I have tried

4条回答
  •  轮回少年
    2021-02-05 06:01

    Here are generic solution that also works in SQLite:

    day = date.today()
    next_day = day + timedelta(days=1)
    my_data = session.query(MyObject).filter(MyObject.date_time >= day,  MyObject.date_time < next_day).all()
    

提交回复
热议问题