CS FundamentalsHardAmazon · Microsoft MCQ pattern

A database stores timestamps in UTC and converts to local time only at the application layer. A query does `WHERE created_at BETWEEN '2024-01-01' AND '2024-01-31'` directly in UTC, but the business requirement was 'all of January in IST (UTC+5:30)'. What subtle bug can this cause?

  1. A. It only affects leap years
  2. B. No bug is possible since dates are always unambiguous
  3. C. Rows from the last few hours of December 31 in UTC (which are already January 1 in IST) or the first few hours of February 1 UTC (still January 31 evening in IST) can be included or excluded incorrectly, because the UTC date boundary doesn't line up with the IST date boundary
  4. D. It would cause a SQL syntax error

Correct answer: C. Rows from the last few hours of December 31 in UTC (which are already January 1 in IST) or the first few hours of February 1 UTC (still January 31 evening in IST) can be included or excluded incorrectly, because the UTC date boundary doesn't line up with the IST date boundary

Because IST is 5.5 hours ahead of UTC, a UTC-based date range filter is shifted relative to the 'local' calendar day boundaries actually intended, systematically miscategorizing rows created near midnight in either timezone — a classic timezone-handling bug when timestamp storage (correctly UTC) and business date semantics (local calendar day) aren't reconciled in the query itself.

More DBMS and SQL questions

Exams that ask this topic