Reputation: 511
I have a requirement to calculate the number of days from 3 different dates. I need to run the logic to get an integer value from below pseudo logic.
(future_date_1 - future_date_2) - Today()
How to achieve this in PostgreSQL?
Upvotes: 5
Views: 15527
Reputation: 17358
In order to achieve the date difference in days,
SELECT DATE_PART('day', '2011-12-31 01:00:00'::timestamp - '2011-12-29 23:00:00'::timestamp);
OR
this also works pretty well
select '2015-01-12'::date - '2015-01-01'::date;
Now, you only need to use this logic and satisfy your requirement.
Upvotes: 5