Reputation: 1191
I'm trying to work out how to filter by a day in a date field. If I have a date of birth field, how do I get every person that has a birthday on the 24th on all the months?
Upvotes: 4
Views: 4211
Reputation: 127200
The extract()
function creates an appropriate EXTRACT(field FROM expr)
expression for the database engine in use. Extract the day
field from the column and compare it to your day value.
session.query(Person).filter(extract('day', Person.birthdate) == 24).all()
Upvotes: 9