'query firestore with timestamp condition
The firestore document has a field: timestamp: "April 4, 2022 at 10:17:30 PM UTC+2" My djangomodel has field: timestamp, when i print it it gives me "2022-04-04 22:19:19.514590+00:00"
I want to retrieve firestore data if timestamp firestore object > djangoObject_timestamp
The query to firestore:
query = query.where(u'timestamp', u'>',timestamp_from_saved_object)
However i get al the data from firestore, so it seems like the query is not working. I am doubting the query code and the date formats, is it right ?
Solution 1:[1]
The problem was in the datetime field in django which i use for the query to firestore. It was 2 hours ahead!. So the query contained the datetime + 2 hours. Thats why i got back the wrong date from firestore.
Solved it with a timedelta
timestamp_from_saved_object = timestamp_from_saved_object - timedelta(hours=2)
The query date is now the right time and i get back the right data from firestore.
Solution 2:[2]
u try in a SQL format with mysql-connector???
query = "SELECT timestamp FROM database WHERE timestamp > "+timestamp_from_saved_object
cursor.execute(query)
the format of dates... whats its your timestamp?? another timestamp of example from your database?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | saro |
| Solution 2 | virollo |
