O'Reilly logo

SQL in a Nutshell by Kevin Kline

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

SET TIME ZONE

Synopsis

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

Vendor

Command

SQL Server

Not supported

MySQL

Not supported

Oracle

Not supported

PostgreSQL

Supported, with variations

SQL99 Syntax and Description

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

Like most SET commands, SET TIME ZONE can be executed only outside of an explicit transaction. The LOCAL clause resets the current-session time values to those of the default time zone for the server. Otherwise, an interval value can be set to increase (with +) or decrease (with -) over the default time.

PostgreSQL Syntax and Variations

SET TIME ZONE {'timezone' | LOCAL | DEFAULT 
| INTERVAL {+ | -}'00:00' HOUR TO MINUTE};

PostgreSQL allows a session’s time value to be set to the server default by using either the LOCAL or DEFAULT clause.

The value specified for time zone is dependent on the operating system. For example, `PST8PDT’ is a valid time zone for California on Linux systems, while `Europe/Rome’ is a valid time zone for Italy on Linux and other systems. If an invalid time zone is specified, the command sets the time zone to Greenwich Mean Time (GMT).

The time zone also may be set as an interval of the default server time zone.

Examples

In the following example, the time zone is advanced three hours over the current default time zone:

SET TIME ZONE INTERVAL +'03:00' HOUR TO MINUTE;

Next, the current time for the current ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required