In order to add weeks to current date in PostgreSQL we will using three approach one by using the + operator, other by using make_interval() and other using the INTERVAL data type. Here are examples of both approaches. Also, we will look at how to Add weeks to Current Date/Time column in PostgreSQL table.
Add weeks to current datetime in PostgreSQL using INTERVAL data type:
We will be Using the INTERVAL data type to add weeks to Current datetime in PostgreSQL. When we add weeks to current datetime using INTERVAL datatype the output will be in datetime(timestamp) format. In below example, we have added 2 weeks to current date using Interval data type.
Example 1:
SELECT CURRENT_DATE + INTERVAL '2 WEEKS' as new_date
Output:
Add weeks to current datetime in PostgreSQL using make_interval() function:
We will be Using the make_interval() function to add weeks to current datetime in PostgreSQL. When we add weeks to current date using the make_interval() function, the output will be in datetime(timestamp) format. In below example, we have added 2 weeks to current date
Example 1:
SELECT CURRENT_DATE::date + make_interval(weeks => 2) as new_date
Output:
Add weeks to current date in PostgreSQL (round about):
To Add weeks to current date in PostgreSQL we will using CURRENT_DATE keyword with addition (+) symbol. Which will add 14 days which is 2 weeks to current date as shown below.
Example 1:
SELECT CURRENT_DATE + 14 AS new_date;
Output:
Add weeks to current datetime column in PostgreSQL table using Interval datatype:
We will be using below fruits table for our example to depict on how to add weeks to current datetime column in postgresql table.
fruits:
We have added 2 WEEKS to current datetime column using INTERVAL datatype in PostgreSQL and new column named new_expiry_date is being created as shown below.
select *,current_date, current_date::timestamp + INTERVAL '2 Weeks' as new_expiry_date from fruits
Output:
Add weeks to current datetime column in PostgreSQL table using make_interval() function:
We have added 2 weeks to current datetime column using make_interval() function in postgresql and new column named new_expiry_date is being created as shown below.
select *,current_date, current_date::timestamp + make_interval(weeks => 2) as new_expiry_date from fruits
Output:
Add WEEKS to current date column in PostgreSQL table using Additional (+) operator:
In this round about method We have added 14 days to current date column using simple addition operator (+) in postgresql and new column named new_expiry_date is being created as shown below.
SELECT *,current_date, current_date+ 14 as new_expiry_date from fruits
Output: