RefLib

Reference library for AI

Back

postgresql_16:3.6.9.4 AT TIME ZONE

PostgreSQL 16 > The SQL Language > Functions and Operators > Date/Time Functions and Operators > AT TIME ZONE

The AT TIME ZONE operator converts time stamp *without* time zone to/from time stamp *with* time zone, and time with time zone values to different time zones. (see functions-datetime-zoneconvert-table) shows its variants.

| Operator Description Example(s) | | --- | | timestamp without time zone AT TIME ZONE *zone* timestamp with time zone Converts given time stamp *without* time zone to time stamp *with* time zone, assuming the given value is in the named time zone. timestamp '2001-02-16 20:38:40' at time zone 'America/Denver' 2001-02-17 03:38:40+00 | | timestamp with time zone AT TIME ZONE *zone* timestamp without time zone Converts given time stamp *with* time zone to time stamp *without* time zone, as the time would appear in that zone. timestamp with time zone '2001-02-16 20:38:40-05' at time zone 'America/Denver' 2001-02-16 18:38:40 | | time with time zone AT TIME ZONE *zone* time with time zone Converts given time *with* time zone to a new time zone. Since no date is supplied, this uses the currently active UTC offset for the named destination zone. time with time zone '05:34:17-05' at time zone 'UTC' 10:34:17+00 |

In these expressions, the desired time zone *zone* can be specified either as a text value (e.g., 'America/Los_Angeles') or as an interval (e.g., INTERVAL '-08:00'). In the text case, a time zone name can be specified in any of the ways described in (see postgresql_16:3.5.5.3). The interval case is only useful for zones that have fixed offsets from UTC, so it is not very common in practice.

Examples (assuming the current (see guc-timezone) setting is America/Los_Angeles): SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'America/Denver'; Result: 2001-02-16 19:38:40-08 SELECT TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/Denver'; Result: 2001-02-16 18:38:40 SELECT TIMESTAMP '2001-02-16 20:38:40' AT TIME ZONE 'Asia/Tokyo' AT TIME ZONE 'America/Chicago'; Result: 2001-02-16 05:38:40 The first example adds a time zone to a value that lacks it, and displays the value using the current TimeZone setting. The second example shifts the time stamp with time zone value to the specified time zone, and returns the value without a time zone. This allows storage and display of values different from the current TimeZone setting. The third example converts Tokyo time to Chicago time.

The function `timezone(*zone*, *timestamp*) is equivalent to the SQL-conforming construct *timestamp* AT TIME ZONE *zone*`.

Back