core-jgi/db/ddlutils/postgresql/functions/Add_Months.sql

12 lines
298 B
PL/PgSQL

CREATE OR REPLACE FUNCTION add_months (datetime TIMESTAMP WITH TIME ZONE, months NUMERIC)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
BEGIN
if datetime is null or months is null then
return null;
end if;
return datetime + (interval '1' month * TRUNC(months));
END;
$$ LANGUAGE plpgsql IMMUTABLE
;