An order placed at 11:30 PM IST on 20 November shows up under 21 November in the finance dashboard and under 20 November in the operations report. A late-night order at 12:45 AM on 21 November appears under 20 November in a third report. Nobody wrote obviously wrong code. Each system simply made a different, unstated assumption about what time it was. Date and time bugs are rarely about arithmetic; they are about meaning.

Instants and wall-clock times are different things

The first idea to get straight is that “a time” can mean two different things.

An instant is a single point on the universal timeline. The moment the customer pressed “Place order” is one instant, the same everywhere on Earth. It can be written in many ways: 23:30 in Chennai, 18:00 in London (UTC), 13:00 in New York in November. All three describe the same instant.

A local date-time, or wall-clock time, is what a clock on a particular wall shows: “20 November, 23:30”. On its own it does not identify an instant, because you do not know whose wall. It only becomes an instant when paired with a time zone.

Then there are plain dates with no time at all: a date of birth, a holiday, the due date on a GST return. A birthday is not midnight in any particular time zone. Storing it as a timestamp invites bugs where people’s birthdays shift by a day when viewed from another region.

Modern libraries model these separately. Java’s java.time has Instant, LocalDateTime, LocalDate and ZonedDateTime; .NET has DateTimeOffset, DateOnly and friends; Python has timezone-aware and naive datetime objects. Choosing the right type is half the battle.

Diagnosing the opening example

India Standard Time is UTC plus 5 hours 30 minutes, with no daylight saving. So 11:30 PM IST on 20 November is 6:00 PM UTC on 20 November. Here is how each report could go wrong.

  • “Tomorrow” in finance. The order service, running on a server set to IST, saved the wall-clock value 23:30 without any zone information. The finance pipeline assumes every stored timestamp is UTC and converts it to IST for display, adding 5:30. The order lands at 5:00 AM on 21 November.
  • Correct in operations. Operations reads the same naive value and treats it as IST, which by luck is right.
  • “Yesterday” for the 12:45 AM order. A third report stores times properly in UTC but groups by the UTC calendar date. 12:45 AM IST on 21 November is 7:15 PM UTC on 20 November, so every order between midnight and 5:30 AM IST is counted on the previous day.

Two separate mistakes are in play. One is storing ambiguous local times. The other is never defining which time zone draws the line between one business day and the next.

Rules that prevent most of this

Store instants as instants. Record event times (orders, logins, payments) in UTC, or in a column type that carries an offset. Databases differ here, so check yours. PostgreSQL’s timestamptz normalises values to UTC on storage and converts them to the session’s time zone on output, while its plain timestamp stores whatever wall-clock value it is given. In MySQL, TIMESTAMP converts using the session time zone while DATETIME does not. Know which behaviour your schema relies on.

Do not rely on server defaults. A JVM, a Node process or a database session picks up a default time zone from the machine. Move a service from an on-premise server in Mumbai to a cloud region defaulting to UTC, and every “now” that quietly used the default changes meaning. Set it explicitly, or better, write code that never depends on it.

Define the business day explicitly. “Daily sales” must mean a calendar day in a named zone, for example Asia/Kolkata. Reports should convert each instant to that zone and then take the date. For a company operating in India and the UAE, finance may want both views; the point is that it is a written decision, not an accident of whichever server ran the query.

Use zone names, not fixed offsets, for anything that involves future or foreign times. India has no daylight saving, so “+05:30” seems enough. But a meeting with a London client at 9:00 AM their time is UTC+0 in January and UTC+1 in July. A named zone like Europe/London carries those rules; an offset does not. Governments also change time zone rules, so for future events (a webinar next year), store the local time plus the zone name and compute the instant close to the event.

Send unambiguous strings over the wire. Use ISO 8601 with an offset or a trailing Z for UTC. A string like “2026-11-20 23:30” in an API payload is an invitation to misinterpretation. JavaScript adds its own trap: by the language specification, a date-only string such as “2026-11-20” is parsed as UTC midnight, while a date-time string without an offset is parsed as local time. In India, the first displays as 5:30 AM when shown in local time.

Edge cases worth testing

  • Events between midnight and 5:30 AM IST, where IST and UTC dates differ.
  • Month-end and financial-year-end (31 March) cut-offs, where a few hours’ error moves revenue between periods.
  • Users or servers in zones with daylight saving, where one local hour is skipped in spring and another repeats in autumn, so “02:30” may not exist or may occur twice.
  • “Today” computed on a server versus on a user’s phone set to a different zone.

Durations deserve a word too. “Add one day” and “add 24 hours” are the same in IST but not in a zone with daylight saving. Subscriptions, SLA timers and loan interest calculations should state which one they mean.

Fixing the opening example in an existing system usually means three steps: migrate the naive column to a proper instant type (deciding, carefully, which zone the old values were actually in), make every report convert to Asia/Kolkata before taking the date, and add tests with timestamps deliberately placed just before and after midnight IST. The migration is the risky part, because getting the assumed zone wrong shifts history by five and a half hours.

Written by the RP Strativa Team. Times and scenarios in the examples are illustrative.

Leave a Reply

Trending