Using DATE_ADD and DATE_SUB in MySQL
📖 Scenario: You work in a small library database. You want to calculate due dates for borrowed books and check overdue dates by adding or subtracting days from the borrow date.
🎯 Goal: Build SQL queries that use DATE_ADD and DATE_SUB functions to calculate new dates based on a borrow date.
📋 What You'll Learn
Create a table called
borrow_records with columns id (integer), borrow_date (date).Insert exactly two rows with
borrow_date values '2024-06-01' and '2024-06-15'.Write a query using
DATE_ADD to find the due date by adding 14 days to borrow_date.Write a query using
DATE_SUB to find the reminder date by subtracting 3 days from the due date.💡 Why This Matters
🌍 Real World
Libraries, rental services, and any system that tracks deadlines use date calculations to manage due dates and reminders.
💼 Career
Database developers and analysts often write queries with date functions to automate scheduling and notifications.
Progress0 / 4 steps