Name

SET TIME ZONE Statement

The SET TIME ZONE statement changes the current session’s time zone if it needs to be different from the default time zone.

Platform

Command

MySQL

Not supported

Oracle

Supported, with variations

PostgreSQL

Supported, with limitations

SQL Server

Not supported

SQL2003 Syntax

SET TIME ZONE {LOCAL | INTERVAL {+ | -}'00:00' [HOUR TO MINUTE]}

Keywords

LOCAL

Sets the current session’s time zone to that of the local server.

INTERVAL

Specifies the time zone offset from Coordinated Universal Time (UTC) in terms of hours and minutes. The offset can be either an increase (with +) or decrease (with -) in relation to the default time.

HOUR TO MINUTE

Specifies the datatype of the TIME ZONE value.

Rules at a Glance

This is a relatively simple command that either sets the user session time zone to that of the server (LOCAL), or sets the time zone in relation to Coordinated Universal Time (formerly Greenwich Mean Time, or GMT). Thus, an INTERVAL of 2 would advance the time zone two hours greater than UTC, while an INTERVAL of -6 would reduce thetime zone by six hours from UTC to the United States central time zone.

Programming Tips and Gotchas

Like most SET commands, SET TIME ZONE can be executed only outside of an explicit transaction. In other words, you do not need to encapsulate the command within a START or BEGIN TRAN and a COMMIT TRAN statement.

MySQL

Not supported.

Oracle

In Oracle9i and higher, you can use the following ALTER SESSION command to set the session time zone:

ALTER SESSION SET ...

Get SQL in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.