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

Instruction

Great. How can we use this function? For instance, we can use it to change the way dates are shown. Take a look:

SELECT
  EXTRACT(DAY FROM launched) ||
  '-' ||
  EXTRACT(MONTH FROM launched) ||
  '-' ||
  EXTRACT(YEAR FROM launched)
FROM aircraft;

As a result, we'll get dates like '10-03-2012' instead of '2012-03-10'. But the query itself… Ugh… this doesn't look very nice.

This is why various databases implement new functions to work with time and date. These functions make such operations easier. However, there is no universal way which would work across most databases. This is why we won't show any of them here.

Exercise

For each route, show its code and the departure time in the following, changed format: hh.mm, where hh is the hour and mm the minutes. Name the second column time.

Stuck? Here's a hint!

Use the concatenation sign || twice and don't forget about the period between the hour and minute.