Home > OS >  Filter records submitted today in SQLite using SQLAlchemy
Filter records submitted today in SQLite using SQLAlchemy

Time:12-15

I am using two databases for different applications. In both applications I want to filter entries by today so I used the following function in Postgres and it works wonderfully.

    query = MyModel.query.filter(cast(MyModel.my_time_stamp, Date) == date.today()).all()

When I change the database to SQLite3, no results are shown. And the output of the query above in SQLite3 is:

>>> print(query) 
>>> []

What I'm looking for is:

Sorting records with timestamp, in SQLite3, and only show the records that have been entered today.

CodePudding user response:

Actually I just found and answer to my question:

from sqlalchemy import func
from datetime import date

query = MyModel.query.filter(func.date(MyModel.my_time_stamp)==date.today()).all()

This would do the job.

  • Related