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

194
Vistas
How to compare if a timestamptz date equal a timestamptz date in Javascript/Postgresql

I got a date in this format when i get my data in my postgresql database like that : 2022-02-20 00:37:11.337937+00

But when i get this from my javascript code i get this result instead : 2022-02-20T00:37:15.279Z

How can i compare this date since 2022-02-20T00:37:15.279Z is cut with a 'Z' at the end. I try to compare strictly exazctly this date : 2022-02-20 00:37:11.337937+00 in my JS backend code.

EDIT: In fact, i can have an array of waht i want, but i can't get value message, and others value in my database. This is the request i have, but i can't get the message property:

SELECT ID, MAX(lastmsg) FROM 
(   SELECT m.receiver AS ID, MAX(m.created_at) as lastmsg FROM message m
WHERE m.sender = '1'
GROUP BY m.receiver
UNION
SELECT m.sender AS ID, MAX(m.created_at) as lastmsg FROM message m
WHERE m.receiver = '1'
GROUP BY m.sender
) as table2 GROUP BY ID ORDER BY max LIMIT 10 OFFSET 0

I found this solution from another post, but i don't know how to get message field, if i change that i have to add it to the GROUP bY but then my result is not the result expected

I tried something like that, but it doesn't work:

SELECT *
FROM  (
    SELECT DISTINCT ON (sender, receiver)
          sender, receiver, message AS msg, created_at AS created_at
    FROM message
    WHERE sender = '1' OR receiver = '1'
    ORDER BY sender, receiver, created_at
) f

I got duplicated value with that

Edit 2: I'm running version 12.2 of Postgresql on a Debian

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

0

You cannot compare the two dates with timestamps. First, you should convert the timestamp into a date format (DD/MM/YY) before executing your query. You can also use the below method as well.

datetime: {
        [Op.gte]: moment(req.body.datetime).startOf('day'),
        [Op.lte]: moment(req.body.datetime).endOf('day'),
      },
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