Date Arithmetic with Intervals in PostgreSQL
📖 Scenario: You are managing a small library database. You want to calculate due dates for borrowed books by adding a fixed loan period to the borrow date.
🎯 Goal: Build a SQL query that adds an interval of days to a borrow date to find the due date for returning books.
📋 What You'll Learn
Create a table named
borrowed_books with columns book_id (integer) and borrow_date (date).Insert three rows with specific
book_id and borrow_date values.Define a variable or use a fixed interval of 14 days representing the loan period.
Write a SELECT query that shows
book_id, borrow_date, and a new column due_date which is borrow_date plus the 14-day interval.💡 Why This Matters
🌍 Real World
Libraries, rental services, and booking systems often need to calculate due dates by adding fixed time intervals to start dates.
💼 Career
Understanding date arithmetic with intervals is essential for database developers and analysts working with time-based data.
Progress0 / 4 steps