Filtering and ordering by date with SQLAlchemy

You want the extract command which is documented here ->

The list of options are generally the same regardless of dialect/SQL server so a reference of types can be seen here for SQLite3

A common base extract type arguments to SQL arguments is here ->

Extract() is transformed for SQLite3 into `strftime` ->

The base visitor/transformer for extract is here

Finally, a basic example might be something like MyTable.query.filter(extract('year', MyTable.date_field) == 2022) which would produce something like SELECT ...hell of a lot of columns... FROM MyTable WHERE STRFTIME("%y", MyTable.date_field);