Best April deals - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dealing with dates
Working with time
Date and time data types in PostgreSQL
Extracting dates and times
Intervals
Timezone conversion
Format date and time
Current date and time data
Summary

Instruction

The results are intervals, which tell us the difference between the two timestamps:

0 years 0 mons 1673 days 23 hours 16 mins 0.00 secs

PostgresSQL provides the interval data type. The simplest way to create an interval in with the syntax:

INTERVAL 'x field'

x is a number, its unit can be any of millennium, century, decade, year, month, week, day, hour, minute, second, millisecond, microsecond, or abbreviations (y, m, d, etc.) or plural forms (months, days, etc.). Example intervals can be:

  • INTERVAL '2 hours'
  • INTERVAL '3 days'
  • INTERVAL '5 months'
  • INTERVAL '1 year'

You can add such intervals to a date/timestamp:

SELECT
  id,
  launched_timestamp,
  launched_timestamp + INTERVAL '1 year' AS new_launched_timestamp
FROM aircraft;

The above query will add one year to each launched timestamp in the aircraft table.

Exercise

PerfectAir decided to use the withdrawn aircraft with ID of 3 once again. Show its original withdrawn timestamp and the withdrawn timestamp postponed by 6 months as the new_launched_timestamp column.