Last active
February 12, 2021 13:06
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from datetime import date | |
from sqlalchemy import cast, DATE | |
Match.query.filter(cast(Match.date_time_field, DATE)==date.today()).all() |
Thank you Jonatan. func.DATE() works.
I've opened an issue sqlalchemy/sqlalchemy#5104
Hi guys,
For SQLite, I'm using thefunc.DATE()
function:from sqlalchemy import func session.query(db.Transaction).filter(func.DATE(db.Transaction.datetime) == date.today())
It worked! Thank you sooo much!
👺it doesn't work with even postgress for me
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
sir when comparison with date return nothing but use less then and greater then code is working
problem with date comparison is not working