PostgreSQL make_timestamptz() Function
The PostgreSQL make_timestamptz()
function creates a timestamp value from the given year, month, day, hour, minute, second, timezone fields.
make_timestamptz()
Syntax
Here is the syntax of the PostgreSQL make_timestamptz()
function:
make_timestamptz(
year INT
, month INT
, day INT
, hour INT
, minute INT
, second DOUBLE PRECISION
[, timezone TEXT]
) -> TIMESTAMP WITH TIME ZONE
Parameters
year
-
Required. An integer indicating the year.
month
-
Required. An integer indicating the month.
day
-
Required. An integer indicating the day.
hour
-
Required. An integer indicating the hour.
minute
-
Required. An integer indicating the minute.
second
-
Required. A double-precision value indicating seconds.
timezone
-
Required. A string indicating the time zone. The default is the current time zone.
Return value
The PostgreSQL make_timestamptz()
function returns a timestamp value created from the given year, month, day, hour, minute, second, and timezone fields.
If the year is negative, it means the date is in BC.
make_timestamptz()
Examples
Here are a few examples showing the basic usage of make_timestampt z()
functions .
SELECT make_timestamptz(2022, 5, 15, 20, 55, 25.517606);
make_timestamptz
-------------------------------
2022-05-15 20:55:25.517606+08
Note that in this example, the timezone of the current session is Asia/Shanghai
.
You can specify a time zone via the timezone
parameter , for example:
SELECT make_timestamptz(2022, 5, 15, 20, 55, 25.517606, 'Europe/London');
make_timestamptz
-------------------------------
2022-05-16 03:55:25.517606+08