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

374
Vistas
convert mongodb creation date to utc +5 for a search filter, by date

Good morning and thanks in advance. I tell you my problem, I am making a filter to search for requests for certain specific elements and when searching for a date in YYY-MMM-DD I had the problem. It turns out that mongo saved it to me with this format:

createdAt 2022-07-10T18:11:28.630+00:00,

updatedAt 2022-07-10T18:11:28.630+00:00

which I was able to "fix" with:

if (payload.date) {
query.createdAt = { 
$gte: new Date(`${payload.date}T00:00:00.000-00:00`), 
$lt: new Date(`${payload.date}T23:59:59.999-00:00`) 
};

but my problem arose that when saving and searching by date, it seems that I save it with timezone zero, so I consult the date 2022-07-11 and it did not bring any data, I tried with 2022-07-12 and it just returned a response of documents.

I think my solution would be to use moment and convert it to utc +5 when doing the query. Does anyone have an idea how I can do that fix? I would appreciate it very much.

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

0

Maybe similar to this

query.createdAt = { 
   $gte: moment.tz(payload.date, "America/Toronto").startOf('day').toDate(), 
   $lte: moment.tz(payload.date, "America/Toronto").endOf('day').toDate()
};
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