python - SqlAlchemy: Convert datetime column to date column -


i'm trying convert datetime column 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 

the error showed: "name 'date' not defined" tried adding import date, , got "importerror:cannot import name 'date'"

maybe i'm doing wrong beginning. please guide.

you have import it.

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 

or can func:

from sqlalchemy import func ... query = query.filter(func.date(db_col) == date_from) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -