Extracting Month from Dates
Often times when working with time series data for analysis, you may be required to extract information from dates such a
the quarter, month, year or even day of the week. For example, analyzing weekend sales may be an interesting exercise to
understand business performance behavior. This short snippet demonstrates how to extract such components from date.
enrollments table
For this exercise, I will use the enrollments table which looks like below
SELECT * FROM enrollments
Extract() Function
Postgresql offers the Extract() function to help us deal with dates. We can simply extract the date
by passing the Month from and the date column.
For example:
SELECT EXTRACT(month from '2025-04-01'::date);
Extract Month from enrollments
Let's put that together in a query on enrollments table.
SELECT enrollment_date,
EXTRACT(year from enrollment_date) AS year,
EXTRACT(month from enrollment_date) AS month,
completion_status
FROM enrollments;