Name

SET TIME ZONE Statement

Synopsis

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

DB2

Not supported

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

Sets an increase (with +) or decrease (with -) over the default time.

INTERVAL

Specifies the time zone offset from Coordinated Universal Time (UTC) in terms of hours and minutes.

HOUR TO MINUTE

Specifies the datatype of the TIME ZONE value.

Rules at a Glance

This is a relatively simple command that sets the user session time zone to that of the server (LOCAL), or sets the time zone in relation to Coordinated Universal Time (UTC) (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 the time 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.

DB2

Not supported.

MySQL

Not supported.

Oracle

In Oracle9i and higher, you can use the following ALTER SESSION ...

Get SQL in a Nutshell, 2nd 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.