Reputation: 485
I want to query firestore collection on timestamp field but only on date (NOT TIME). For example I have three records in my database like these:
when I try to query with 07/07/2019 to 09/07/2019, result showing only 1 record, instead of 2. I think its due to time.
I checked this link (Firestore query by dates and times separately) but its not related with my query.
My query in code:
Date dateFrom = "21/07/2019";
Date dateTo = "24/07/2019";
Query MyQuery = mFirestore.collection("students")
.whereGreaterThanOrEqualTo("entered", dateFrom)
.whereLessThanOrEqualTo("entered", dateTo);
I think this is due to different time in database. Please help me to solve this issue.
Upvotes: 1
Views: 1566
Reputation: 930
The problem is that when you pass date in query, it automatically append 00:00:00 time. So if you want to query with 07/07/2019 to 09/07/2019, I will advise you to try to add 1 day more to your last date. So in this particular example you should set 07/07/2019 to 10/07/2019. Or maybe another solution is to append on second date 23:59:59 timestamp.
Upvotes: 2