Add minutes to CURRENT_TIMESTAMP in PostgreSQL

postgresql

Solution

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;

Problem

I have a procedure in PostgreSQL that I want to add the number of minutes to CURRENT_TIMESTAMP like below timestamp_var := CURRENT_TIMESTAMP + interval '20 minutes'; But the number of minutes is a parameter. Do we have the functions to do this? Pls help me in this case ``` CREATE OR REPLACE FUNCTION modify_time(id users.id%TYPE, min integer) AS $$ BEGIN UPDATE users SET modified_at = CURRENT_TIMESTAMP WHERE user_id = id; END $$ LANGUAGE plpgsql; ``` I want to add min minutes to CURRENT_TIMESTAMP thanks

Original source