in the definition of my table, I have a column defined as follows:
created_date = Column(DateTime, nullable=False, default=datetime.now)
I want to request an instance when its created date is equal to the current date (for example, if it was created today).
so I tried something like this:
res = session.query(Object).filter(datetime.now() == Object.created_date)
it never works because the two dates are compared in seconds, I think, therefore they will never be equal to each other. then I tried this:
res = session.query(Object).filter((datetime.now() - Object.created_date).days < 1)
while (datetime.now() - datetime.now()).days works in python, it does not work in my situation here. I received an error message: “BinaryExpression Object” or “Comparator” does not have the “days” attribute.
So, how do I make a query that filters instances created on the current day? thanks!
source share