I just got started using Flask SQLAlchemy and I looked over here to see how I am supposed to do a query between so I found this
But the problem that I got is that it returns the following when executes as below:
SELECT records.id AS records_id, records.created_at AS records_created_at, records.file_type AS records_file_type, records.path_filename AS records_path_filename
FROM records
WHERE records.created_at BETWEEN ? AND ?
Code:
today_date = datetime.today().strftime("%d/%m/%Y")
week = (datetime.today() - timedelta(days=7)).strftime("%d/%m/%Y")
month = (datetime.today() - timedelta(days=30)).strftime("%d/%m/%Y")
last_30_days = db.session.query(Records).filter(Records.created_at.between(month, today_date))
And when I add .all()
at the end of the last_30_days expression it returns an empty list.
I would also like to mention that when I use just the same expression to query the week, today_date it gets all the results.
This is how the table looks like:
class Records(db.Model):
id = db.Column(db.Integer, primary_key=True)
created_at = (db.Column(db.String(20), nullable=False))
file_type = (db.Column(db.String(100), nullable=False))
path_filename = db.Column(db.String(120), unique=True, nullable=False)
Could anybody explain to me please what's going on? Thanks!