Mysql
 sql >> Database >  >> RDS >> Mysql

Come confrontare le date in sqlalchemy?

Che ne dici di usare datetime.datetime oggetti invece di stringhe per fromDate , toDate ?

from datetime import datetime, timedelta

def findAll(fromDate, toDate):
    fromDate = datetime.strptime(fromDate, '%Y-%m-%d')
    toDate = datetime.strptime(toDate, '%Y-%m-%d') + timedelta(days=1)
    return session.query(SomeType).filter(
        SomeType.date >= fromDate,
        SomeType.date < toDate).all()