0

I am using this query :

firebase.firestore().collection('questions')
        .where('created', '>=', new Date(date[0]))
        .where('created', '<=', new Date(date[1]))

Querying based on start date for eg : 20 nov and end date for eg : 21 nov for created field timestamp present in Firestore,if start date and end date is same it is not returning any data, and if start date is 20 Nov and end date 21 Nov it returns only a few data of 20 Nov, not all the data of 20 Nov data

SAME DATES : date[0] -> Wed Nov 20 2019 09:17:49 GMT+0530 (India Standard Time) date1 -> Wed Nov 20 2019 09:17:49 GMT+0530 (India Standard Time)

DIFF DATES date[0]- Wed Nov 20 2019 09:17:49 GMT+0530 (India Standard Time) date1 -Sat Nov 23 2019 09:17:49 GMT+0530 (India Standard Time)

enter image description here

  • This question was already solved here https://stackoverflow.com/questions/53524187/query-firestore-database-on-timestamp-field . I would recommend you to keep your code more segregate and do not instantiate Date objects inside the query. Anyway, I think that the problem is that the Date objects are not getting the value you think they are. There should be the problem. – Andrei Tigau Nov 22 '19 at 09:38
  • What's the question? – Alex Mamo Nov 22 '19 at 10:25
  • If you're having trouble reading data with this query, edit your question to make sure it contains all information we need (in a minimal form). 1) Right now we have no way to know what `date[0]` and `date[1]` are, while those are probably part of the problem. Try to reproduce the problem with hard-coded dates, or simply log the values before the query and include that logging output in your question. 2) Also include a screenshot of a document that you think should be matched by this query, but that isn't being returned. – Frank van Puffelen Nov 22 '19 at 15:32
  • Any ideas guys, I am facing this issue because of timestamp based on time, it returns the document, if time is 11:07 in the timestamp , it returns me all the documents after 11:07.. not the documents which are present in firestore for 10:00 too – Lohitha Yalavarthi Nov 25 '19 at 05:38
  • Your same issue has been solved in this link https://stackoverflow.com/questions/47000854/firestore-query-by-date-range, you can also try converting the timestamps to miliseconds and filter by that – bhito Nov 26 '19 at 08:32
  • milliseconds deosnt help too because it takes seconds as consideration and return me the documents after that seconds. – Lohitha Yalavarthi Nov 27 '19 at 08:09
  • You can also try the following [suggestion](https://stackoverflow.com/a/53003159/11641073) that was made in the link i provided you. Forcing the timestamps to be treated as Dates in the settings. – bhito Nov 27 '19 at 14:03

0 Answers0