// dialect comparison

Convert a timestamp to another timezone in SQL Server, PostgreSQL, MySQL, SQLite and Oracle

Named zones versus fixed offsets, and which engines know the difference at all.

Filed under Types & casting

The verdict

PostgreSQL and Oracle have the most honest model: store the instant with its zone, convert at the edges. SQL Server's double AT TIME ZONE idiom works but trips people up, MySQL depends on loaded tables, and SQLite leaves zones to the application.

Where they differ

Real timezone conversion needs a zone database (DST rules change). PostgreSQL, Oracle and SQL Server know named zones; MySQL does if you loaded the tables; SQLite never does.

How each engine writes it

SQL Server

SELECT SYSDATETIMEOFFSET() AT TIME ZONE 'Pacific Standard Time';

AT TIME ZONE (2016+) converts a value that has an offset; on a naive datetime it labels the value as that zone. Windows zone names only ('Pacific Standard Time', not IANA), listed in sys.time_zone_info.

PostgreSQL

SELECT NOW() AT TIME ZONE 'America/Los_Angeles';

On timestamptz it converts and returns a naive timestamp in that zone; applying it to a naive timestamp instead labels the value. IANA zone names.

MySQL

SELECT CONVERT_TZ(UTC_TIMESTAMP(), '+00:00', 'America/Los_Angeles');

Named zones need the time zone tables in the mysql schema loaded; without them CONVERT_TZ returns NULL. '+00:00' style offsets always work but know nothing about DST.

SQLite

SELECT DATETIME('now', '-8 hours');

No zone database: only fixed-offset modifiers. DST transitions must be computed by hand or in the app.

Oracle

SELECT SYSTIMESTAMP AT TIME ZONE 'America/Los_Angeles',
  FROM_TZ(TIMESTAMP '2026-11-20 12:00:00', 'UTC') AT TIME ZONE 'America/Los_Angeles'
FROM dual;

TIMESTAMP WITH TIME ZONE values carry the zone and AT TIME ZONE converts them; FROM_TZ labels a naive timestamp first. IANA names come from the database's time zone file, so DST rules are only as current as that file.

Questions that come up

Why does SQL Server need AT TIME ZONE twice?

The first call tells SQL Server what zone a naive datetime is in (it gains an offset); the second converts to the target. GETUTCDATE() AT TIME ZONE 'Pacific Standard Time' would mislabel the UTC time as Pacific.

Are MySQL's named zones available by default?

No. The tz tables must be populated (mysql_tzinfo_to_sql on Linux). On untouched Windows servers or hosted setups, only offset-based CONVERT_TZ is guaranteed.

Should I store UTC or store the zone with the timestamp?

Store UTC when only one instant matters; store timestamptz/timestamp with time zone when events happen in a region and you must preserve which zone they were scheduled in (e.g. recurring meetings).

Keep reading

// write it once, run it anywhere

Switch engines without relearning SQL

SQLly is a native SQL workbench for macOS, Windows and Linux. Its formatter and plan viewer work in all five dialects.