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

Instruction

Correct again! Now, let's see how we can manipulate dates, times 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 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 (name the column month). Show the column withdrawn as the second column for reference.

Stuck? Here's a hint!

Use EXTRACT(MONTH FROM withdrawn).