Reputation: 99
How can I retrieve documents that have a createdAt timestamp newer than a certain date?
Something like:
firstDayOfMonth = datetime.date.today().replace(day=1)
transactions = db.collection('productTransactions').where('createdAt', ">=", firstDayOfMonth).get()
Upvotes: 2
Views: 2463
Reputation: 1399
The problem is that your firstDayOfMonth
is of class date
, while the Firebase uses format Timestamp
for dates and time (which is datetime
in Python).
You can do:
firstDayOfMonth = datetime.date.today().replace(day=1)
# datetime.date(2019, 2, 1)
dt = datetime.datetime.combine(firstDayOfMonth, datetime.datetime.min.time())
# datetime.datetime(2019, 2, 1, 0, 0)
transactions = db.collection('productTransactions').where('createdAt', ">=", dt).get()
Upvotes: 6