Introduction
Dates
Time
Timestamps
Extract functions
23. EXTRACT - example
Timezone conversion
Intervals
Current date and time
Revision

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 database. This is why we don'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.

Stuck? Here's a hint!

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

Console

Code editor

Result

TableConsole