3

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

Community
  • 1
  • 1
dived
  • 31
  • 1
  • 3

2 Answers2

5

Try this:

from sqlalchemy import func
import datetime
DBSession.query(Order)\
    .filter(func.ADDDATE(Order.create_time,1)>datetime.datetime.now())
noa1
  • 131
  • 1
  • 5
0

presto:

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

extract('dow', cast(cast(t_table.open_time, TIMESTAMP) - 5,TIMESTAMP)) == 3
EstevaoLuis
  • 2,422
  • 7
  • 33
  • 40
sanphi
  • 1
  • 2
    Welcome to Stack Overflow! Please don't answer just with source code. Try to provide a nice description about how your solution works. See: [How do I write a good answer?](https://stackoverflow.com/help/how-to-answer). Thanks – sɐunıɔןɐqɐp Jul 26 '18 at 09:08