Introduction
Dates
Time
Timestamps
Extract functions
22. EXTRACT(field FROM column)
Timezone conversion
Intervals
Current date and time
Revision

Instruction

Correct again! Now, let's see how we can manipulate dates, time and timestamps. SQL provides a special function:
EXTRACT(field FROM column). Here field is one of the following: DAY, MONTH, YEAR, HOUR, MINUTE, SECOND.

Take a look:

SELECT EXTRACT(YEAR FROM launched) AS year
FROM aircraft
ORDER BY year;

The above query will extract the year from the column launched for each aircraft and will show it in the ascending order.

The function EXTRACT is not supported by SQL Server. SQL Server has a similar function called datepart.

Exercise

Extract and show the month of each withdrawn date in the table aircraft. Show the column withdrawn as the second column for reference.

Stuck? Here's a hint!

Use EXTRACT(MONTH FROM withdrawn).

Code editor

TableConsole