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?

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.