Back

Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
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

Welcome to Intellipaat Community. Get your technical queries answered by top developers!

28.4k questions

29.7k answers

500 comments

94k users

Browse Categories

...