Thread: Adding dates in plpgsql

Adding dates in plpgsql

From
Stuart Grimshaw
Date:
I have a trigger that needs to do some addition to dates,

CREATE FUNCTION update_dis_record () RETURNS OPAQUE AS '
DECLARE
    tmpYellow INTEGER;
    tmpBan_Starts timestamp;
BEGIN
    tmpYellow := NEW.yellow % 5;
    tmpBan_Starts := now + "14 Days";
    IF tmpYellow = 0 AND NEW.yellow <> 0 THEN
        NEW.length := NEW.length + 1;
        NEW.ban_starts := tmpBan_Starts;
    END IF;

    IF NEW.ban_starts <> null THEN
        NEW.ban_starts := OLD.ban_starts;
    END IF;

    RETURN NEW;
END;
' LANGUAGE 'plpgsql';

The line "tmpBan_Starts := now + "14 Days"; " doesn't work obviously, but
what is the correct way to ad 14 (or any number of ) days to a date with
plpgsql?

--

| Stuart Grimshaw <stuart@footballnet.com>
| Chief Operations Officer
| Football Networks Ltd
|-
| t:07976 625221
| f:0870 7060260

Re: Adding dates in plpgsql

From
Richard Welty
Date:
On Thu, 25 Oct 2001 14:04:14 +0100 Stuart Grimshaw <stuart@smgsystems.co.uk> wrote:

> I have a trigger that needs to do some addition to dates,

see the following:

http://techdocs.postgresql.org/techdocs/faqdatesintervals.php

the interval stuff is really quite nice.

richard
--
Richard Welty                                    Averill Park Networking
rwelty@averillpark.net                                      518-573-7592