Skip to content
Advertisement

How to check if two dates are the same with timestamp

I have two dates. One I get from the database, the other is which one I want to pass. How can I check if these two are the same? These are timestamp with time zones

In this case they are the same.

% timestamp_coloumn is my column where the value is in it
SELECT *
    FROM public.tbl_text
WHERE ('2021-06-02T06:33:51.485Z' - timestamp_coloumn) = 0;

%What I hand over: 2021-06-02T06:33:51.485Z

%Stands in the database: 2021-06-02 06:33:51.485093+00 = timestamp_coloumn

Advertisement

Answer

SELECT *
    FROM public.tbl_text
    WHERE 
      '2021-06-02T06:33:51.485Z'::timestamptz = 
       date_trunc('milliseconds', timestamp_coloumn);
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement