News for hackers. Stuff that matters.
Re:PostgreSQL's Missing DateDiff Function by saltcured on Wednesday December 22, 2021 @02:32PM (#29653933)
I'm pretty sure this will provide the desired semantics, though I am away from a usable postgres and not bothering to test it.

CREATE FUNCTION date_diff(granularity text, t1 timestamptz, t2 timestamptz) RETURNS int8 AS $$ SELECT date_part(granularity, date_trunc(granularity, t2) - date_trunc(granularity, t1))::int8 $$ LANGUAGE SQL;

There are no comments on this comment yet.