Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
Username DateStart DateFinish James 2017-07-01 2017-09-14 Luigi 2017-08-02 2017-09-18 Francesco 2017-09-03 2017-10-25
How calculate with sql difference between two date columns in days?
select *, "DateFinish" - "DateStart"
You can simply subtract them like
select "DateFinish"::date - "DateStart"::date;
And if the dates column are of datatype date then you can simply do:
select "DateFinish" - "DateStart"
Add a comment
If you want to see the difference in a number (10 instead of a date value that has 10 days in it), you can obtain it with:
select extract(day from "DateFinish" - "DateStart")
extract
Try this. It extracts the number of days between 2 dates and creates a column called "days":
select extract(day from DateFinish - DateStart) as days from MyTable;
Required, but never shown
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.
Explore related questions
See similar questions with these tags.
select *, "DateFinish" - "DateStart"?..