Convert UTC Event Timestamps to Local Dates per User Timezone
Last updated: November 29, 2026
Quick Overview
Facebook app sessions are logged with UTC timestamps, and a users table stores each user's IANA timezone. Return daily active users by local calendar date and country, where a user counts once per local day.
Meta
November 29, 20260
0
0 solved
Facebook app sessions are logged with UTC timestamps, and a users table stores each user's IANA timezone. Return daily active users by local calendar date and country, where a user counts once per local day.
Meta reports engagement in local time for many markets, and a UTC day boundary can shift a large share of sessions in countries like India or Brazil. This screen question checks timezone-aware conversion in pandas, the per-row versus per-group conversion trick, and correct distinct counting.
What the Interviewer Expects
- Parse timestamps as UTC-aware before converting
- Convert per timezone group because a Series holds a single timezone
- Take the local date after conversion, not before
- Count distinct users per local date and country
- Have a fallback for users with a missing timezone
Key Topics to Cover
How to Approach This
- Clarify the schema and expected output format before writing queries.
- Use CTEs (WITH clauses) to break complex queries into readable steps.
- Consider window functions (ROW_NUMBER, RANK, LAG, LEAD) for ranking and sequential analysis.
- Watch for NULLs, duplicates, and edge cases in JOINs and GROUP BY.
- For pandas, prefer vectorized operations over row-by-row iteration.
Possible Follow-up Questions
- How would daylight saving transitions affect a day with 23 or 25 hours?
- Which timezone should you use for a user who travels?
- How would you make this vectorized for 100 million rows?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice SQL ProblemsSample Answer
Clarify the Data
sessions(user_id, ts_utc) with naive UTC timestamps; users(user_id, country, tz) with names like 'Asia/Kolkata'. Users with no tz default to UTC, and I will say that explicitly. Output: `local_dat...
Approach
Join sessions to users. A pandas datetime Series can only carry one timezone, so I group by tz and convert each group with dt.tz_localize('UTC').dt.tz_convert(tz), then take .dt.date. Grouping b...