Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Dealing with dates
Working with time
Date and time data types in PostgreSQL
Extracting dates and times
23. The DATE_PART() function
Timezone conversion
Format date and time
Current date and time data
Summary

Instruction

Super! Now, let's see how we can manipulate dates, times, and timestamps. PostgreSQL provides a special function:

DATE_PART(part, source)

Here part is one of the following: day, month, year, hour, minute, second, etc. And source is one of the date and time data types.

Take a look:

SELECT DATE_PART('year', launched_timestamp) AS year
FROM aircraft
ORDER BY year;

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

Exercise

For each aircraft show the id, the withdrawn_timestamp column and the withdrawn_month column (extracted month from the withdrawn_timestamp column).

Stuck? Here's a hint!

Use this expression:

DATE_PART('month', withdrawn_timestamp) AS withdrawn_month