Skip to content

Instantly share code, notes, and snippets.

@danielthiel
Last active February 12, 2021 13:06
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save danielthiel/8374607 to your computer and use it in GitHub Desktop.
Save danielthiel/8374607 to your computer and use it in GitHub Desktop.
SQLAlchemy: filter by date for an datetime field(does not work with SQLite, with PostgreSQL it works fine)
from datetime import date
from sqlalchemy import cast, DATE
Match.query.filter(cast(Match.date_time_field, DATE)==date.today()).all()
@FabricioPatrocinio
Copy link

FabricioPatrocinio commented Feb 12, 2021

This worked for me:

from sqlalchemy import func
table_db = Youtable.query.filter(func.DATE(Youtable.date_bd) == your_date)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment