Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dates
Time
Timestamps
Extract functions
Timezone conversion
Intervals
Current date and time
Review

Instruction

Okay! There is one more syntax for intervals. It is not in SQL Standard, but most databases support it. The syntax is as follows:

  • INTERVAL '2' HOUR
  • INTERVAL '3' DAY
  • INTERVAL '5' MONTH
  • INTERVAL '1' YEAR
  • etc.

In MySQL you use the syntax without the apostrophes: INTERVAL 2 HOUR, INTERVAL 3 DAY, etc.

As usual, you can add such intervals to a timestamp/date (or subtract it):

SELECT id,
  launched + INTERVAL '3' MONTH
FROM aircraft;

The above query will add 3 months to the timestamp stored in the column launched.

Exercise

PerfectAir has changed its schedules. All flights which depart after 1:00 PM have been delayed by 1 hour. Show the code of each route together with the new departure (as new_departure) and arrival times (as new_arrival).

Stuck? Here's a hint!

Use + INTERVAL '1' HOUR.