Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Postgresql difference between two columns dates?

Tags:

postgresql

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?

like image 890
James Avatar asked Oct 19 '17 09:10

James


1 Answers

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"
like image 142
Rahul Tripathi Avatar answered Sep 23 '22 10:09

Rahul Tripathi