In PostgreSQL, we can use the +
operator to add one or more minutes to a time value.
By “time” value, this could be an actual time
value, a timestamp
, or an interval
. We can also add minutes to a date
value or a date
and time
combination.
Example
We can specify intervals when adding to dates and times. So to add one or more minutes, we can use minute
or minutes
:
SELECT time '07:00' + interval '1 minute';
Result:
07:01:00
Plural
And in plural form:
SELECT time '07:00' + interval '25 minutes';
Result:
07:25:00
Timestamps
And here it is with a timestamp
value:
SELECT timestamp '2030-01-20 09:00' + interval '30 minutes';
Result:
2030-01-20 09:30:00
Intervals
We can also add minutes to an interval
:
SELECT interval '5 hours' + interval '2 minutes';
Result:
05:02:00
Dates
We can even add minutes to a date
value:
SELECT date '2030-01-20' + interval '90 minutes';
Result:
2030-01-20 01:30:00
The result is a timestamp
value.
Date & Time Values Combined
We can also add a date
and time
value together, and add minutes to that:
SELECT date '2030-01-20' + time '01:00' + interval '55 minutes';
Result:
2030-01-20 01:55:00
Specified in Seconds
Another way to do it is to specify the equivalent number in seconds:
SELECT time '15:45' + interval '60 seconds';
Result:
15:46:00
When doing this, it doesn’t have to be exactly a minute:
SELECT time '15:45' + interval '93 seconds';
Result:
15:46:33
Negative Values
It’s possible to perform date arithmetic with negative values. If we use a negative value with the +
operator, then the specified number of minutes will be subtracted from the input date/time. But if we use it with the -
operator, then it will be added to the input date/time.
Example:
SELECT time '03:00' - interval '-2 minutes';
Result:
03:02:00