Skip to content Skip to sidebar Skip to footer

Select Date From Timestamp In Sqlalchemy

I'm using SQLAlchemy with python and i want to select date from column type timestamp, to do this query: SELECT DATE(`record_date`) FROM Users I made this code by sql alchemy but

Solution 1:

give an alias

SELECTDATE(`record_date`) as record_d FROM Users

then use this

 session.query(Users.record_d).all()

If want do it directly then ,try this

your_dates = session.query(cast(Users.record_date, DATE)).all()

EDIT:

your_dates = session.query(func.DATE(Users.record_date)).all()

Post a Comment for "Select Date From Timestamp In Sqlalchemy"