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
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.