0

I've a field name called PurchaseDate in every document of Cloud Firestore. Now I want to get all documents where the year in PurchaseDate is 2019.

In Firestore date timestamp is store as below screenshot

enter image description here

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Sabir Syed
  • 422
  • 3
  • 19

1 Answers1

0

When using the following lines of code:

String queryDate = "16-01-2019"; 
database.collection("Abcdt/currenUser/EFC").whereEqualTo("PurchaseDate", queryDate).get();

It means that you are trying to query the database using a literal String, which is not correct since in your database your PurchaseDate property is of type Date. So to solve this, instead of passing as a the second argument a String, pass a Date object.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • can you please share the Date object how to pass the same – Sabir Syed Jan 28 '19 at 09:22
  • [This](https://stackoverflow.com/questions/6510724/how-to-convert-java-string-to-date-object) is how you can convert your `queryDate` String to a Date object. Does it work now? – Alex Mamo Jan 28 '19 at 09:24
  • request to kindly suggest the complete code to convert the same – Sabir Syed Jan 28 '19 at 10:07
  • 1
    Stack Overflow isn **not** a code writing service. You should make your own attempt given the information in the answer and ask another question if something else comes up. – Alex Mamo Jan 28 '19 at 10:11
  • Hi Alex, still my issue not resolved. For temporarily I have completed the task with other option. Otherwise, can you please suggest to get the result with Year only. – Sabir Syed Jan 29 '19 at 14:24
  • Hi Sabir, I think this approach is better: https://stackoverflow.com/a/59502494/2860701 – Alberto Dec 27 '19 at 15:20