How to Add Minutes to a Time in PostgreSQL

Postgres offers numerous temporal data types, such as TIME, DATE, INTERVAL, and TIMESTAMP. These data types assist us in storing or manipulating the DateTime values efficiently. Postgres allows us to perform numerous tasks on these DateTime values using different built-in functions and operators. One such operator is the “+” operator.

The addition “+” operator has extended functionalities, however, this write-up explains how to add minutes to time, date, timestamp, or interval using the “+” operator.

How to Add Minutes to a Time Using “+” Operator?

In Postgres, the “+” operator allows us to add minutes to a specific time, date, interval, or timestamp. Let’s understand it using the following examples.

Example 1: Adding Minutes to a Specific Time

In the following code, “35” minutes are added to a specific time:

SELECT TIME '05:00' + INTERVAL '35 Minutes';

Here, TIME and INTERVAL represent built-in temporal data types.

img

The specified minutes have been added to the given time.

Example 2: Adding Minutes to Current Time

In the following code, “35” minutes are added to the current time:

SELECT CURRENT_TIME, CURRENT_TIME + INTERVAL '35 Minutes';
img

The specified minutes have been added to the current time.

Example 3: Adding Minutes to a Specific Timestamp

In the following code snippet, “75” minutes are added to a specific timestamp:

SELECT TIMESTAMP '2022-12-31 23:30:30' + INTERVAL '75 Minutes';
img

The given minutes have been successfully added to the input timestamp.

Example 4: Adding Minutes to Current Timestamp

In this example, “75” minutes are added to the current timestamp:

SELECT CURRENT_TIMESTAMP + INTERVAL '75 Minutes';
img

The given minutes have been successfully added to the current timestamp.

Example 5: Adding Minutes to a Specific Interval

Let’s learn how to add minutes to a specific interval using the “+” operator:

SELECT INTERVAL '3 years 2 months 4 days 2 hours 1 minute 30 seconds' + INTERVAL '75 Minutes';
img

“75” minutes have been added to a specific interval using the “+” operator.

Example 6: Adding Minutes With Current Date

In the below snippet, “75” minutes are added to the current date using the “+” operator:

SELECT CURRENT_DATE + INTERVAL '75 Minutes';
img

The output shows that the specified minutes have been successfully added to the current date.

Example 7: Adding Seconds to Specific Minutes

In the below snippet, “180” seconds are added to the specified minutes using the “+” operator:

SELECT TIME '00:05:00' + INTERVAL '180 Seconds';
img

The specified seconds have been added to the given minutes.

Conclusion

In PostgreSQL, the “+” operator is used to add minutes to the current or specific DateTime values. Where the DateTime value can be a date, interval, time, or timestamp. We can specify the INTERVAL data type While adding the minutes with DateTime values. The addition “+” operator has extended functionalities, however, in this write-up, we have learned how to add minutes to time, date, timestamp, or interval using the “+” operator.