Data Analysis Best Practices

Chapter 2 · Practice 4 of 4

Decide on one time zone and convert timestamps explicitly

From Read the data correctly

Why it matters

"Orders on 1 October" means different rows in UTC and in local time. If one table stores UTC and another stores local time, a daily join can shift a day's worth of rows.

  • Find out which time zone each timestamp column uses.
  • Convert to one analysis time zone before truncating to dates.
  • Write the chosen time zone in the chart titles and the write-up.
sql
-- PostgreSQL: count orders per local calendar day in Karachi time
select (ordered_at at time zone 'Asia/Karachi')::date as order_day,
       count(*) as orders
from orders
group by 1
order by 1;