Calculating the expected return date
So now that you've practiced how to add and subtract timestamps and perform relative calculations using intervals, let's use those new skills to calculate the actual expected return date of a specific rental. As you've seen in previous exercises, the rental_duration
is the number of days allowed for a rental before it's considered late. To calculate the expected_return_date
you will want to use the rental_duration
and add it to the rental_date
.
This exercise is part of the course
Functions for Manipulating Data in PostgreSQL
Exercise instructions
- Convert
rental_duration
by multiplying it with a 1-dayINTERVAL
. - Add it to the rental date.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
SELECT
f.title,
r.rental_date,
f.rental_duration,
-- Add the rental duration to the rental date
___ '1' day ___ f.___ + ___ AS expected_return_date,
r.return_date
FROM film AS f
INNER JOIN inventory AS i ON f.film_id = i.film_id
INNER JOIN rental AS r ON i.inventory_id = r.inventory_id
ORDER BY f.title;