how to using dateadd in sqlalchemy with filter?

主宰稳场 提交于 2021-02-05 06:31:28

问题


The sql expression :

select * 
  from order 
 where status=0 
   and adddate(created_time, interval 1 day)>now();

python code:

from sqlalchemy.sql.expression import func, text
from datetime import datetime 

closed_orders = DBSession.query(Order).filter(func.dateadd(Order.create_time,         text('interval 1 day'))>datetime.now()).all() 

but it's got wrong. how to do it correctly?

thanks

REF :Using DATEADD in sqlalchemy


回答1:


Try this:

from sqlalchemy import func
import datetime
DBSession.query(Order)\
    .filter(func.ADDDATE(Order.create_time,1)>datetime.datetime.now())



回答2:


presto:

extract('hour', cast(t_table.open_time,TIMESTAMP)) - 5 == 12

extract('dow', cast(cast(t_table.open_time, TIMESTAMP) - 5,TIMESTAMP)) == 3


来源:https://stackoverflow.com/questions/18267454/how-to-using-dateadd-in-sqlalchemy-with-filter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!