Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

190
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda