Calculate difference between two queries's timestamp output in postgresql

Viewed 17

I have two queries with me, each gives a timestamp as an output.

1. select createdon from table1 where condition1;
2. select createdon from table1 where condition2;

Both the outputs are like this,

2022-06-26 16:05:04

The query I wrote is like this:

select extract epoch from ((Select createdon from table1 where condition1) - (select createdon from table1 where condition2);

But I'm not getting any output. How can I calculate the difference between these timestamps in days and hours?

1 Answers

you ca use this sql for extract interval

select ((Select createdon from table1 where condition1) - (select createdon from table1 where condition2))::interval;
Related