5

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?

4
  • 2
    You need to be more precise, what exactly you need? the day value of a date; the numeric count of a date since 1900 in milliseconds; the number of days between date_1, date_2, and today? be more specific please. Commented Sep 13, 2017 at 18:23
  • I need number of days between date_1, date_2, and today. Commented Sep 13, 2017 at 18:42
  • 1
    This question does not seem to makes sense. An integer cannot express days between 3 dates. You would need to clarify. And all the basic information like data types and Postgres version are missing. too. Commented Sep 13, 2017 at 19:59
  • edit your question and add some sample data and the expected output based on that data. Formatted text please, no screen shots. Do not post code or additional information in comments Commented Sep 13, 2017 at 21:37

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.