Why do billing and analytics disagree on daily revenue?
Question
Finance reports daily revenue by New York business day (America/New_York), while your analytics table groups the same orders by UTC date. Look at five orders around Sunday, 8 March 2026 (when New York springs forward from EST -05:00 to EDT -04:00 at 07:00 UTC):
| Order | UTC timestamp | New York local time | Amount |
|---|---|---|---|
ord_1 | 2026-03-08T02:30:00Z | 2026-03-07 21:30 EST | $300 |
ord_2 | 2026-03-08T04:15:00Z | 2026-03-07 23:15 EST | $200 |
ord_3 | 2026-03-08T15:00:00Z | 2026-03-08 11:00 EDT | $400 |
ord_4 | 2026-03-09T01:30:00Z | 2026-03-08 21:30 EDT | $600 |
ord_5 | 2026-03-09T03:45:00Z | 2026-03-08 23:45 EDT | $500 |
- What is March 8 revenue under UTC versus New York, and why do they differ by
$600? - How do spring-forward (
23h) and fall-back (25h) DST days distort hourly and daily metrics? - How should you store and query timestamps so both teams agree?
Show hints (3)
- "CHECK TOTAL REVENUE"
Sum all five orders first (
$2,000). Both pipelines see the same$2,000, so the$600gap is purely a date-boundary shift. - "COUNT DST HOURS"
New York's 8 March 2026 skips
02:00to02:59(23hours total). Its 1 November 2026 repeats01:00to01:59(25hours total). - "STORE UTC CONVERT LATE"
Persist every event as a UTC instant (
TIMESTAMPTZor RFC 3339Z), then convert at query time with an IANA zone name likeAmerica/New_York.
Show checked explanation
March 8 revenue is $900 in UTC (ord_1 to ord_3) versus $1,500 in New York (ord_3 to ord_5), a $600 shift even though both sum to $2,000. Store every timestamp as a UTC instant and convert at query time using an IANA zone name (America/New_York), never a fixed offset. Normalize DST days by 23 or 25 elapsed hours.
from datetime import datetime, timedelta, timezone EST, EDT = timezone(timedelta(hours=-5)), timezone(timedelta(hours=-4)) DST_START = datetime(2026, 3, 8, 7, 0, tzinfo=timezone.utc) ORDERS = [ ("2026-03-08T02:30:00Z", 300), ("2026-03-08T04:15:00Z", 200), ("2026-03-08T15:00:00Z", 400), ("2026-03-09T01:30:00Z", 600), ("2026-03-09T03:45:00Z", 500), ] utc_day, ny_day = {}, {} for ts, amt in ORDERS: dt = datetime.fromisoformat(ts) tz = EDT if dt >= DST_START else EST utc_d = dt.date().isoformat() ny_d = dt.astimezone(tz).date().isoformat() utc_day[utc_d] = utc_day.get(utc_d, 0) + amt ny_day[ny_d] = ny_day.get(ny_d, 0) + amt print("UTC:", utc_day) print("NY :", ny_day)
UTC: {'2026-03-08': 900, '2026-03-09': 1100}
NY : {'2026-03-07': 500, '2026-03-08': 1500}UTC vs New York daily buckets, DST day lengths (23h and 25h), and fixed-offset drift run on CPython 3.12.10 (Windows x64) against the sample orders above; official IANA, RFC 3339, PostgreSQL, and Python links checked. Checked by an editor other than the author.
Walkthrough
No orders disappeared. Across all five rows, both dashboards sum to $2,000. The $600 gap on March 8 happens because New York sits 4 to 5 hours behind UTC, so late-evening US orders land on the next UTC date:
ord_1($300) andord_2($200) happen on March 7 evening in New York (21:30and23:15 EST), yet UTC puts$500into March 8.ord_4($600) andord_5($500) happen on March 8 evening in New York (21:30and23:45 EDT), yet UTC pushes$1,100into March 9.- Net shift on March 8:
+$1,100 - $500 = +$600($1,500New York vs$900UTC).
| Reporting date | UTC bucket | New York bucket | Difference (NY - UTC) |
|---|---|---|---|
2026-03-07 | $0 | $500 | +$500 |
2026-03-08 | $900 | $1,500 | +$600 |
2026-03-09 | $1,100 | $0 | -$1,100 |
| Total | $2,000 | $2,000 | $0 |
Why Daylight Saving Time (DST) makes daily and hourly charts lie:
- Spring forward (
2026-03-08): New York midnight (05:00 UTC) to next midnight (04:00 UTC) lasts only 23 hours. Local02:00to02:59never happens, creating a fake zero-traffic hour and a-4.2%(23/24 - 1) dip in daily totals. - Fall back (
2026-11-01): Midnight (04:00 UTC) to next midnight (05:00 UTC) lasts 25 hours. Local01:00to01:59occurs twice (05:00 UTCin EDT and06:00 UTCin EST). Grouping by naive local hour doubles the01:00bar and inflates daily totals by+4.2%(25/24 - 1). - Fixed-offset bug: Hardcoding
-05:00breaks as soon as EDT starts. An order at2026-03-09T04:30:00Zis00:30 EDTon March 9, yet-05:00puts it at23:30on March 8 for the next eight months.
The reliable warehouse pattern:
SELECT (created_at AT TIME ZONE 'America/New_York')::date AS ny_day, SUM(amount_usd) AS revenue_usd FROM orders GROUP BY 1 ORDER BY 1;
Store every event timestamp as an unambiguous UTC instant (TIMESTAMPTZ in PostgreSQL, RFC 3339 Z in logs). Convert at query time with a full IANA zone name (America/New_York in SQL or Python's ZoneInfo with tzdata), never a fixed offset or local server time.
Common mistakes
- Subtracting a fixed 5 hours (
INTERVAL '5 hours') for Eastern Time. Every order between00:00and00:59 EDTlands on the wrong business day from March through October. - Storing naive local timestamps without an offset or zone. During the fall-back hour (
01:00to01:59), two real hours collapse into one ambiguous wall-clock time. - Relying on the database session's default time zone. A BI tool connecting from
UTCand a finance job running inAmerica/New_Yorksilently produce different dates from the same query. - Comparing raw 23-hour or 25-hour DST days against normal 24-hour days without normalizing by elapsed hours (
-4.2%and+4.2%swings look like real business shocks).
Follow-up questions
- "Should global metrics like DAU use UTC or each user's local time zone?" Use one canonical reporting zone (usually UTC or company headquarters time) for financial totals and company-wide dashboards so daily sums match exactly. Use the user's local zone only for local-habit features like daily streaks or morning notifications.
- "How do you avoid a broken chart during the 25-hour fall-back day?" Bucket hourly series by UTC instant (
date_trunc('hour', created_at)in UTC) and format the axis labels with the offset (01:00 EDT,01:00 EST). For daily KPI alerts, monitor rate per hour or 7-day rolling totals. - "Why are abbreviations like EST or CST unsafe in SQL or Python configs?" Abbreviations are ambiguous (
CSTmeans US Central, China, or Cuba) and do not switch automatically on DST dates. Always pass full IANA names such asAmerica/New_YorkorEurope/London.
What a strong answer covers
Reconciles the $600 March 8 gap ($900 UTC vs $1,500 NY) while confirming total revenue is $2,000. Explains 23-hour, 25-hour, and fixed-offset DST traps, and prescribes UTC storage with explicit IANA query-time conversion.
Open in interactive practice deck →