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
Post a Comment