MulaiMulai sekarang secara gratis

Interval data types

INTERVAL data types provide you with a very useful tool for performing arithmetic on date and time data types. For example, let's say our rental policy requires a DVD to be returned within 3 days. We can calculate the expected_return_date for a given DVD rental by adding an INTERVAL of 3 days to the rental_date from the rental table. We can then compare this result to the actual return_date to determine if the DVD was returned late.

Let's try this example in the exercise.

Latihan ini adalah bagian dari kursus

Functions for Manipulating Data in PostgreSQL

Lihat Kursus

Petunjuk latihan

  • Select the rental date and return date from the rental table.
  • Add an INTERVAL of 3 days to the rental_date to calculate the expected return date`.

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

SELECT
 	-- Select the rental and return dates
	___,
	___,
 	-- Calculate the expected_return_date
	rental_date + ___ ___ AS expected_return_date
FROM rental;
Edit dan Jalankan Kode