I have 2 subqueries which give me a result consisting of dates.
I would like to calculate the difference between them.
For example:
SELECT DATEDIFF(
DAY,
(SELECT MAX(invoices.date) FROM invoices WHERE invoices.orderno = odH.orderno),
(SELECT min(history.date) FROM history WHERE history.orderno = odH.orderno)
) ...
2
Answers
To calculate the difference between two dates in Postgres, you can simply subtract one date from the other. Here’s how you can modify your query:
This will give you the difference in days between the maximum INVOICE date and the minimum history date for a given order number.
There is no
DATEDIFF
in Postgres. You can simplify your query to: