I am looking for a way to implement the SQLServer-function datediff in PostgreSQL. That is,
This function returns the count (as a signed integer valu
@WebWanderer 's answer is very close to the DateDiff using SQL server, but inaccurate. That is because of the usage of age() function.
e.g. days between '2019-07-29' and '2020-06-25' should return 332, however, using the age() function it will returns 327. Because the age() returns '10 mons 27 days" and it treats each month as 30 days which is incorrect.
You shold use the timestamp to get the accurate result. e.g.
ceil((select extract(epoch from (current_date::timestamp -