In order to subtract minutes from datetime(timestamp) in PostgreSQL we will be using the make_interval() function and another approach by using the – operator and Interval. datatype. Here are examples of the approach. Also, we will look at how to Subtract minutes from datetime(timestamp) column in PostgreSQL table.
Subtract minutes from date in PostgreSQL using INTERVAL data type:
We will be Using the INTERVAL data type to subtract minutes from datetime in PostgreSQL. When we subtract minutes from datetime(timestamp) using INTERVAL datatype the output will be in datetime(timestamp) format. In below example, we have subtracted 1 minute from datetime using Interval data type.
Example 1:
SELECT '2024-02-24 12:00:00'::timestamp - INTERVAL '1 minutes' AS new_datetime
Output:
Subtract minutes from datetime in PostgreSQL using make_interval() function:
We will be Using the make_interval() function to subtract minutes from datetime in PostgreSQL. When we subtract minutes from datetime using the make_interval() function, the output will be in datetime(timestamp) format. In below example, we have subtracted 1 minutes from timestamp
Example 1:
SELECT '2024-02-24 12:00:00'::timestamp - make_interval(mins => 1) as new_datetime
Output:
Subtract minutes from datetime(timestamp) column in PostgreSQL table using Interval datatype:
We will be using below student_detail1 table for our example to depict on how to subtract minutes from datetime(timestamp) column in PostgreSQL table.
student_detail1:
We have subtracted 2 minutes from date column using INTERVAL datatype in PostgreSQL and new column named new_date is being created as shown below.
select *, birthdaytime::timestamp - INTERVAL '2 MINUTES' as new_date from student_detail1
Output:
Subtract minutes from datetime column in PostgreSQL table using make_interval() function:
We will have subtracted 2 minuntes from datetime column using make_interval() function in PostgreSQL and new column named new_date is being created as shown below.
select *,birthdaytime::timestamp - make_interval(mins => 2) as new_date from student_detail1
Output: