Unit 4, lesson 2 · Adding days, INTERVAL
Moving a date: adding days and intervals
When does the return window close?
The orders table has a delivered_date column, empty for orders that have not arrived. Add a whole number to a date and PostgreSQL moves it by that many days: DATE '2026-03-17' + 7 gives '2026-03-24', and DATE '2026-03-01' - 1 gives '2026-02-28'. The month and year roll over for you. For months or years, add an INTERVAL: DATE '2026-03-17' + INTERVAL '1 month' gives March 17 plus one month, April 17. CURRENT_DATE is today's date, which is how a live report asks for the last 30 days: order_date >= CURRENT_DATE - 30.
SELECT id, order_date,
order_date + INTERVAL '1 month' AS one_month_later
FROM orders
LIMIT 5;Your task
Customers can return an order up to 30 days after it is delivered. For every order with the status returned, show the id, the delivered_date and the last day it could be returned, 30 days after delivery, as return_by.
Tables you will use: orders
Try it in your browserFree, no sign-up. Your query is checked as you go.