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
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'),
},