Postgresql difference between two columns dates?

前端 未结 3 1414
遇见更好的自我
遇见更好的自我 2021-01-18 05:15
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 calcu

相关标签:
3条回答
  • 2021-01-18 05:33

    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;
    
    0 讨论(0)
  • 2021-01-18 05:48

    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"
    
    0 讨论(0)
  • 2021-01-18 05:53

    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") 
    
    0 讨论(0)
提交回复
热议问题