// dates & times reference

SQL set session time zone

Declares the zone in which zone-aware values render for this connection: storage stays UTC, display follows the session.

Kategorie
Dates & times
Returns
session setting
In this category
113 of 121

Syntax

SET TIME ZONE 'Europe/Paris'
SET time_zone = 'Europe/Paris'

Each block is a separate form. The support table and the examples show which engine takes which.

Engine-Unterstützung

EngineSupportNotizen
SQL Server Not built in no session zone; AT TIME ZONE per query instead
PostgreSQL Ja SET TIME ZONE / SET timezone
MySQL Ja SET time_zone; offsets work without tz tables, names need them
SQLite Not built in no concept; 'localtime' modifier uses the OS zone
Oracle Ja ALTER SESSION SET TIME_ZONE

Beispiele

PostgreSQL

SET TIME ZONE 'Europe/Paris'; SELECT now();

MySQL

SET time_zone = '-05:00'; SELECT created_at FROM logs;  -- TIMESTAMP columns shift, DATETIME columns do not

Oracle

ALTER SESSION SET TIME_ZONE = 'America/New_York';

Gut zu wissen

  • Only display and naive-timestamp interpretation change: a timestamptz column returns different text per session but compares, sorts and indexes identically.
  • MySQL's SET time_zone with a named zone needs the tz tables loaded, exactly like CONVERT_TZ; otherwise use offsets like '+02:00'.
  • The session zone also feeds LOCALTIMESTAMP, CURRENT_TIMESTAMP in Oracle, and the parsing of zone-less timestamps into timestamptz; 'naive 14:30' becomes a different instant per session.

Questions about Session time zone

Does SET TIME ZONE rewrite my data?

No. The stored instant is immutable. Only rendering and the interpretation of zone-less input depend on it.

How do I set the zone for one query only?

On PostgreSQL, SET LOCAL TIME ZONE inside a transaction reverts at COMMIT or ROLLBACK. Otherwise convert per expression with AT TIME ZONE, which leaves other queries alone.

Browse every function in the SQL function reference, or see what the SQLly desktop app does for your database.

Cheat sheets for the engines that have it: PostgreSQL, MySQL, Oracle.

// fewer lookups

Functions your engine actually has

SQLly's completion lists the built-in functions of the engine you're connected to, whether that's SQL Server, PostgreSQL, MySQL, SQLite or Oracle. Hover a function for help, and signature hints show each argument as you type.