Time zones and DST
Overview
An offset tells you the difference from UTC at a particular instant. A named time zone describes rules that can change by date, including daylight saving time (DST). A local clock reading can occur twice or not occur at all during a transition.
First example
SQLite 3.46.1.
SELECT datetime('2025-01-01 12:00:00+02:00'), datetime('2025-01-01 10:00:00Z');Observed rows (JSON notation):
[ [ "2025-01-01 10:00:00", "2025-01-01 10:00:00" ]]How it works
PostgreSQL timestamp with time zone represents an instant; it does not retain the original zone name. AT TIME ZONE converts between local timestamps and instants, with direction depending on input type. SQLite accepts numeric offsets in its date functions but does not provide PostgreSQL-style named-zone conversion. Avoid host localtime in reproducible tests. A local calendar day across a DST transition can have 23 or 25 elapsed hours.
Practical example
SQLite 3.46.1.
SELECT (unixepoch('2025-03-31 00:00:00+02:00') - unixepoch('2025-03-30 00:00:00+01:00')) / 3600 AS elapsed_hours;Observed rows (JSON notation):
[ [ 23 ]]Practice and common mistakes
The second query supplies the offsets explicitly for the fictional report day matching Stockholm spring transition on 2025-03-30; it tests arithmetic, not SQLite named-zone rules. Practice: compare two 02:30 clock readings with +02:00 and +01:00 offsets. They are distinct instants one hour apart.
PostgreSQL 17 — not executed
SELECT EXTRACT(EPOCH FROM ((TIMESTAMP '2025-03-31 00:00:00' AT TIME ZONE 'Europe/Stockholm') - (TIMESTAMP '2025-03-30 00:00:00' AT TIME ZONE 'Europe/Stockholm'))) / 3600;Expected result: 23 hours, subject to installed time-zone rules.