9

I am wondering how to filter firebase firestore by date field, as I can't see data type other than String, Number, Boolean

As below, please advice if someone find a way to filter firestore collection based on date field.

enter image description here

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Fahad
  • 749
  • 6
  • 12
  • I tried with different string format unfortunately no luck, – Fahad Jan 26 '21 at 02:35
  • One way to filter by dates in the Firebase console is to save the date as an ISO formatted string instead of their `timestamp` type. Then you can do comparisons/filter with any date, you just need to make it into an ISO strings. Example ISO string: `2023-02-27T20:02:00.361Z`. In javascript you can use the `.toISOString()` function. – InvisibleGorilla Feb 27 '23 at 20:09

3 Answers3

2

I think it's not possible at the moment. I found this documentation on GCP which is practically the same UI. There is a little bit about filtering, but not many details.

I think that this UI is just for support/test purposes not for everyday use so such feature is not really needed. It's working with API with no problem ( you can check example in JS in this SO question).

If you need this feature you should raise a Feature Request here.

vitooh
  • 4,132
  • 1
  • 5
  • 16
0

I believe the only thing you can do at this point is apply a filter on your timestamp fields and set the sort order without a condition. The results will show the timestamp field value so it is easy to scan for the time range you are interested in.

Obviously this is not awesome for large document sets where the interesting date is somewhere in the middle but at least sort order will let choose if you want to scroll from the first or last documents by date.

This approach is described in a Firebase Blog post: Sort and Filter in the Firestore Console

ajbarry
  • 1
  • 1
0

Nowadays it's actually possible to query collections by timestamp fields in the Firebase Console UI using the Query Builder (accessible in the "Firestore Database" view).

Firebase Console Query Builder

Source: This answer by Kariem

sceee
  • 1,681
  • 19
  • 34