← All posts

Time zone bugs in a SaaS app: store everything in UTC

Appointments an hour off, invoices dated the day before, reminders sent at the wrong time: the cause is almost always time zone handling.

Time zone bugs in a SaaS app: store everything in UTC

Key points

  • Store every date in UTC; convert only for display.
  • Save each user’s zone (Europe/Paris, not +01:00).
  • Daylight saving creates hours that do not exist or happen twice.

As soon as an app has users in several countries, or simply crosses a clock change, dates become a trap. On our SaaS projects, one simple rule prevents nearly all of it.

The rule: UTC in storage, local on screen

Server, database and API deal only in UTC. Conversion to local time happens last, in the UI or the outgoing email. Set the server zone explicitly:

// PHP
date_default_timezone_set('UTC');

// MySQL (per connection)
SET time_zone = '+00:00';

Store the zone, not the offset

“+01:00” is wrong for half the year in Paris. Store the IANA identifier (Europe/Paris, America/Toronto): it knows past and future clock changes.

$utc = new DateTimeImmutable($row['starts_at'], new DateTimeZone('UTC'));
$local = $utc->setTimezone(new DateTimeZone($user->timezone));
echo $local->format('Y-m-d H:i');

In the browser, Intl.DateTimeFormat().resolvedOptions().timeZone gives the user’s zone at sign-up.

Daylight saving traps

  • In spring, the hour from 2:00 to 3:00 does not exist: a reminder set for 2:30 local time must shift.
  • In autumn, 2:30 happens twice: say which one, or schedule in UTC.
  • A “daily at 9am” job is defined in the user’s local time and converted to UTC for each occurrence.

Dates without a time

A birthday or an invoice due date has no time zone. Store it as a plain date (DATE, “2026-11-15”), not as UTC midnight, or it will show as the previous day for users further west.

FAQ

TIMESTAMP or DATETIME in MySQL?

TIMESTAMP converts using the connection zone; DATETIME stores as-is. Both work if the connection is fixed to UTC. Just be consistent.

How do I test this?

Run tests under several zones and with dates near clock changes: that is where the bugs show up.

Facing this on your site or app? We diagnose and fix it.

Share LinkedIn Facebook X WhatsApp
</>

webtestudio

Web agency: custom WordPress sites, premium themes and SaaS software.

Discuss your project →