The table below shows the available scalar functions for TIMESTAMPTZ values.
Since these functions do not involve binning or display,
they are always available.
Name
Description
current_timestamp
Current date and time (start of current transaction).
get_current_timestamp()
Current date and time (start of current transaction).
TIMESTAMPTZ values are cast to and from strings using offset notation.
This will let you specify an instant correctly without access to time zone information.
For portability, TIMESTAMPTZ values will always be displayed using GMT offsets:
Named time zone parsing (such as parsing a time zone name from a string and casting it to a representation in the local time zone) relies on ICU time zone support.
TIMESTAMPTZ '1992-03-27 01:02:03' - INTERVAL 5 DAY
1992-03-22 01:02:03
Adding to or subtracting from infinite values produces the same infinite value.
Addition and subtraction of intervals uses the ICU Calendar add function.
For positive intervals (forwards in time) the fields are incremented from least to most significant.
For negative intervals (backwards in time) the fields are decremented from most to least significant.
This produces the same results as Postgres, but does not match some more recent calendar RFCs.
Parses string to a TIMESTAMP WITH TIME ZONE if a %Z element is present in the format, otherwise to a TIMESTAMP, according to the format string.
time_bucket(bucket_width, timestamptz[, offset])
Truncate timestamptz to a grid of width bucket_width. The grid is anchored at 2000-01-01 00:00:00+00:00[ + offset] when bucket_width is a number of months or coarser units, else 2000-01-03 00:00:00+00:00[ + offset]. Note that 2000-01-03 is a Monday.
time_bucket(bucket_width, timestamptz[, origin])
Truncate timestamptz to a grid of width bucket_width. The grid is anchored at the origin timestamp, which defaults to 2000-01-01 00:00:00+00:00 when bucket_width is a number of months or coarser units, else 2000-01-03 00:00:00+00:00. Note that 2000-01-03 is a Monday.
Truncate timestamptz to a grid of width bucket_width. The grid is anchored at the origin timestamp, which defaults to 2000-01-01 00:00:00 in the provided timezone when bucket_width is a number of months or coarser units, else 2000-01-03 00:00:00 in the provided timezone. The default timezone is 'UTC'. Note that 2000-01-03 is a Monday.
The signed number of part boundaries between starttimestamptz and endtimestamptz, inclusive of the larger timestamp and exclusive of the smaller timestamp.
Truncate timestamptz to a grid of width bucket_width. The grid is anchored at 2000-01-01 00:00:00+00:00[ + offset] when bucket_width is a number of months or coarser units, else 2000-01-03 00:00:00+00:00[ + offset]. Note that 2000-01-03 is a Monday.
Truncate timestamptz to a grid of width bucket_width. The grid is anchored at the origin timestamp, which defaults to 2000-01-01 00:00:00+00:00 when bucket_width is a number of months or coarser units, else 2000-01-03 00:00:00+00:00. Note that 2000-01-03 is a Monday.
Truncate timestamptz to a grid of width bucket_width. The grid is anchored at the origin timestamp, which defaults to 2000-01-01 00:00:00 in the provided timezone when bucket_width is a number of months or coarser units, else 2000-01-03 00:00:00 in the provided timezone. The default timezone is 'UTC'. Note that 2000-01-03 is a Monday.
Generate a table of timestamps in the closed range (including both the starting timestamp and the ending timestamp), stepping by the interval.
range(timestamptz, timestamptz, interval)
Generate a table of timestamps in the half open range (including the starting timestamp, but stopping before the ending timestamp), stepping by the interval.
Generate a table of timestamps in the half open range (including the starting timestamp, but stopping before the ending timestamp), stepping by the interval.
The table below shows the ICU scalar functions that operate on plain TIMESTAMP values. These functions rely on ICU time zone support.
These functions assume that the TIMESTAMP is a “local timestamp”.
A local timestamp is effectively a way of encoding the part values from a time zone into a single value.
They should be used with caution because the produced values can contain gaps and ambiguities thanks to daylight savings time.
Often the same functionality can be implemented more reliably using the struct variant of the date_part function.
Name
Description
current_localtime()
Returns a TIME whose GMT bin values correspond to local time in the current time zone.
current_localtimestamp()
Returns a TIMESTAMP whose GMT bin values correspond to local date and time in the current time zone.
localtime
Synonym for the current_localtime() function call.
localtimestamp
Synonym for the current_localtimestamp() function call.
timezone(text, timestamp)
Use the date parts of the timestamp in GMT to construct a timestamp in the given time zone. Effectively, the argument is a “local” time.
timezone(text, timestamptz)
Use the date parts of the timestamp in the given time zone to construct a timestamp. Effectively, the result is a “local” time.
The AT TIME ZONE syntax is syntactic sugar for the (two argument) timezone function listed above. Like that function, it relies on ICU time zone support:
Query
SELECTTIMESTAMP'2001-02-16 20:38:40' AT TIME ZONE 'America/Denver'AS ts;
Result
ts------------------------ 2001-02-17 03:38:40+00
The TIMESTAMP WITH TIME ZONE spelling of the input type is also not accepted by the parser in this build:
Query
SELECTTIMESTAMPWITHTIME ZONE '2001-02-16 20:38:40-05' AT TIME ZONE 'America/Denver'AS ts;
Result
error syntax error at or near "WITH"
Numeric timezones are not allowed either:
Query
SELECTTIMESTAMP'2001-02-16 20:38:40-05' AT TIME ZONE '0200'AS ts;
Functions applied to infinite dates will either return the same infinite dates
(e.g., greatest) or NULL (e.g., date_part) depending on what “makes sense”.
In general, if the function needs to examine the parts of the infinite temporal value,
the result will be NULL.
Adding calendar intervals such as INTERVAL '1 day' to a
TIMESTAMPTZ uses the ICU time zone operators described above.
The interval is added in terms of the calendar fields, so the result
adjusts around a daylight saving time transition rather than simply
adding a fixed number of hours:
Query
SELECT(TIMESTAMPTZ '2025-03-29 02:30:00+01'+INTERVAL'1 day') AT TIME ZONE 'Europe/Amsterdam'AS amsterdam_wall;