Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

571
Vistas
Firestore: can't match midnight with date filter in where() clause

I realized there is a strange behavior when using a where() clause on a Timestamp field in a Firestore query(). I'm using the modular version 9 of Firebase.

Maybe someone has an explanation for that.

So here's the data I see in the Firebase/Firestore console:

enter image description here

Assuming, that today is the 27th December 2021, I want to query all documents for this day - in this case, only the one document from above.

I would use the following query (i.e. everything after today at midnight and before tomorrow at midnight):

const today = new Date(new Date().setHours(0,0,0));
const tomorrow = new Date(new Date(today).setDate(today.getDate() + 1));
const docQuery = query(collection(getFirestore(firebaseApp), 'ticks1'),
    where('date', '>=', today),
    where('date', '<', tomorrow)
)
const querySnapshot = await getDocs(docQuery)
console.log('documents count:', querySnapshot.docs.length)

But: this returns no results!

documents count: 0

Instead, if I change the value in the database to 12:00:01 AM (see below), it works and I retrieve the expected document.

enter image description here

documents count: 1

Can somebody explain this behavior - or is it a bug in the Firestore implementation?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Alternative solution I'm using at the moment

Instead of the range [today 12:00:00 AM, tomorrow 12:00:00 AM) , I'm using this date range now: (yesterday 11:59:59 PM, today 11:59:59 PM]

const now = new Date()
const dateFrom = new Date(new Date(new Date(now).setDate(now.getDate() - 1)).setHours(23,59,59))
const dateTo = new Date(new Date(dateFrom).setDate(dateFrom.getDate() + 1));
const docQuery = query(collection(getFirestore(firebaseApp), 'ticks1'),
    where('date', '>', dateFrom),
    where('date', '<=', dateTo)
)
const querySnapshot = await getDocs(docQuery)
console.log('documents count:', querySnapshot.docs.length)
documents count: 1

At least this makes sense, even though it looks a bit odd.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda