'Compare dates using ORM

I have a table containing column A of type "timestamp with time zone".

I want to get elements from this table having A >= now with timezone - 30 minutes

So I tried this code:

b = db.query(models.My_Class).filter(models.My_Class.A >= datetime.now(pytz.utc) + timedelta(minutes=-30)).first()

Expected result:

  • getting a record if exist with a date respecting this condition

  • getting none if no records respects this condition

Actual result:
I'm getting a record not satisfying the condition

Is there something wrong in my query?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source