On Mon, 2012-12-17 at 11:54:20 -0800, Gabriel Pozo wrote: > I am a new user of sqlalchemy, I need to know how I can filter the > weekdays, to exclude Saturdays and Sundays. > I look for something similar to the function dayofweek of MySQL.
In SQLAchemy you can refer to DB functions via func[0] construct. Say, you have the following model: class Model(Base): __tablename__ = 'foo' id = Column(Integer, primary_key=True) date = Column(DateTime) You can query it like this: session.query(Model).filter( # 1 = Sunday, 2 = Monday, ..., 7 = Saturday. func.dayofweek(Model.date).between(2, 6) ).all() [0] http://docs.sqlalchemy.org/en/rel_0_8/core/expression_api.html#sqlalchemy.sql.expression.func -- Audrius Kažukauskas http://neutrino.lt/
pgpCIaDFcPczZ.pgp
Description: PGP signature