postgres get time difference as timestamp code example
Example 1: postgres date difference seconds
-- difference in seconds between two dates
select extract(epoch from ('2020-03-30 09:55:56'::timestamp - '2020-03-30 08:54:55'::timestamp));
-- result : 3661
Example 2: postgresql get difference in hours between two dates
select EXTRACT(
EPOCH FROM now() - (now() - INTERVAL '5 HOUR')
)/3600
-- it will return 5