0

I wish to keep all objects from the database which have a particular datetime field with values before the current day. I can see how you an filter with hardcoded dates or between two dates, but how can I keep all items with dates before today?

KZiovas
  • 3,491
  • 3
  • 26
  • 47

1 Answers1

0

So it seems it is quite straight forward you can do direct datetime comparison in SQLAlchemy queries like this:

    q = DBSession.query(User).filter(
        User.sign_up_date <= datetime.now() - datetime.timedelta(hours=1),
    )

which would return all user objects which signed up one hour ago.

KZiovas
  • 3,491
  • 3
  • 26
  • 47