Extracting Day of Week from Date
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
ISODOW
The
Monday --> 1
Tuesday --> 2
Wednesday --> 3
Thursday --> 4
Friday --> 5
Saturday --> 6
Sunday --> 7
For example:
SELECT EXTRACT(isodow from '2025-04-01'::date);
Extract Day of Week from enrollments
Let's put that together in a query on enrollments table.
SELECT enrollment_date,
EXTRACT(isodow from enrollment_date) AS day_of_week,
EXTRACT(month from enrollment_date) AS month,
completion_status
FROM enrollments;