Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

In the PostgreSQL, I want to determine the distinction between the two dates.

In the SQL Server, it's much easier:

DATEDIFF(Day, MIN(joindate), MAX(joindate)) AS DateDifference;

I am attempting using the below script.

(Max(joindate) - Min(joindate)) as DateDifference;

Is my method correct and Is there any function in the PostgreSQL to calculate the same?

1 Answer

0 votes
by (12.7k points)
edited by

Your calculation is right for DATE types, though, if your values are timestamps, you should reasonably 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

Also, note the timestamp difference being 1 second less than 2 full days.

Want to become an expert in SQL? Join the SQL online course fast!

Related questions

Browse Categories

...