Add minutes to CURRENT_TIMESTAMP in PostgreSQL

You can multiply intervals by integers. The following gives you a timestamp 20 minutes in the future:

select current_timestamp + (20 * interval '1 minute')

Or, as murison mentions in another answer to this question, there is a more succinct way to express this:

select current_timestamp + (20 ||' minutes')::interval

So, your code could look like:

CREATE OR REPLACE FUNCTION modify_time(id users.id%TYPE, min integer) AS $$ 
BEGIN
UPDATE
        users
    SET
        modified_at = CURRENT_TIMESTAMP + (min * interval '1 minute')
    WHERE
        user_id = id;
END
$$ LANGUAGE plpgsql;

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)