Katkat

Convert Dates to Calendar Quarter Labels in SQL/Python

Point72Data Scientist · Technical Screen

Last updated

This question evaluates a candidate's ability to perform date/time data transformation and normalization in SQL or Python, focusing on converting raw numeric dates into standardized quarter labels for aggregation and reporting.

Transactions

+----+-----------+ | id | trans_dt | +----+-----------+ | 1 | 20230115 | | 2 | 20230402 | | 3 | 20230930 | | 4 | 20231201 | +----+-----------+

Scenario

Financial reporting needs quarterly sales aggregation from raw numeric dates.

Question

Given a table of transactions where the date is stored as an 8-digit integer (YYYYMMDD), write SQL and/or Python code that converts each date into its calendar quarter label (e.g., 20230215 → 2023_Q 1).

Hints

Convert to date type, extract month, map month to quarter with CASE or arithmetic.