Home Calculate difference between dates - Postgres
Reply: 1

Calculate difference between dates - Postgres

Abhijit
1#
Abhijit Published in 2017-09-13 18:15:56Z

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 PostgresSQL?

a_horse_with_no_name
2#
a_horse_with_no_name Reply to 2017-09-13 21:36:51Z

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.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.312321 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO