Autumn Offers - hours only!Up to 80% off on all courses and bundles.-Close
Dealing with dates
Working with time
Date and time data types in PostgreSQL
Extracting dates and times
27. The EXTRACT() function
Timezone conversion
Format date and time
Current date and time data


Nice! Now observe that similar to the DATE_PART() function is EXTRACT(), which gets a the part of the date and time. Here's the syntax:

EXTRACT(part FROM source)

part is one part of the date and time like: second, minute, hour, day, month, year, etc. source is date and time (timestamp). As you noticed, this function requires the keyword FROM between part and source.

The query below returns the year of the produced_date of the aircraft:

SELECT EXTRACT(year FROM produced_date) AS produced_year
FROM aircraft;


For each route show its code and the hour of the departure time (as departure_hour).

Stuck? Here's a hint!

Use this expression:

EXTRACT(hour FROM departure_time) AS departure_hour