Skip to content Skip to sidebar Skip to footer

Sqlalchemy: Convert Datetime Column To Date Column

I'm trying to convert the datetime column to date def filter_between_dates(query, req, db_col): date_from = req.get_param('date_from') #date_to = req.get_param('da

Solution 1:

You have to import it.

from sqlalchemy import Date, cast
...
deffilter_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 you can do it with func:

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

Post a Comment for "Sqlalchemy: Convert Datetime Column To Date Column"