How to calculate DATE Difference in PostgreSQL?

后端 未结 4 1398
既然无缘
既然无缘 2021-02-01 16:23

Here I need to calculate the difference of the two dates in the PostgreSQL.

In SQL Server: Like we do in SQL Server its muc

4条回答
  •  醉梦人生
    2021-02-01 17:01

    Your calculation is correct for DATE types, but if your values are timestamps, you should probably use EXTRACT (or DATE_PART) to be sure to get only the difference in full days;

    EXTRACT(DAY FROM MAX(joindate)-MIN(joindate)) AS DateDifference
    

    An SQLfiddle to test with. Note the timestamp difference being 1 second less than 2 full days.

提交回复
热议问题