我正在尝试将datetime
列转换为date
def filter_between_dates(query, req, db_col):
date_from = req.get_param('date_from')
#date_to = req.get_param('date_to')
query = query.filter(cast(db_col,DATE) == date_from)
return query
错误显示:"name 'DATE' is not defined"
我尝试添加import DATE
,然后得到了
"ImportError:cannot import name 'DATE'"
也许我从一开始就做错了。请指导。
答案 0 :(得分:3)
你必须导入它。
> get.variables(lprec)
[1] 28.60000 0.00000 0.00000 31.82759
或者你可以用func:
来做from sqlalchemy import Date, cast
...
def filter_between_dates(query, req, db_col):
date_from = req.get_param('date_from')
#date_to = req.get_param('date_to')
query = query.filter(cast(db_col,Date) == date_from)
return query