2

I am tring to query to a Firestore database to a collection and filter by date. I have a Timestamp field (dateStart) and i need to get the results have date today , i don't care about time ,i tried to use this but it works only have same time

My document : 20 septembre 2021 at 01:30:00 UTC+1

refWallet
  .where("dateStart", "==", new Date("2021,09,20"))
  .get()
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Achraf
  • 141
  • 10

1 Answers1

2

You will need a range query with start and end points to cover the intended time. In Firestore, timestamp types are always considered a single point in time and do not have date and time components available. It's the same for Date objects in JavaScript.

refWallet
  .where("dateStart", ">=", startDate)
  .where("dateStart", "<", endDate)
  .get()

If this is not what you want, then you probably shouldn't use a timestamp type field and instead use a string that will give you an exact match. For example, you could store dates as strings formatted YYYYMMDD in order to query for exact dates without ranges.

Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • i make this colRef = query(colRef, where("createdDate", ">=", q1), where("createdDate", "<", q2)) but still not works – Nanda Z Jul 08 '23 at 04:33