How to calculate DATE Difference in PostgreSQL?

后端 未结 4 1437
既然无缘
既然无缘 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:19

    a simple way would be to cast the dates into timestamps and take their difference and then extract the DAY part.

    if you want real difference

    select extract(day from 'DATE_A'::timestamp - 'DATE_B':timestamp);
    

    if you want absolute difference

    select abs(extract(day from 'DATE_A'::timestamp - 'DATE_B':timestamp));
    

提交回复
热议问题