Contents
make_timestamptz()
A function for creating a timestamptz from individual values
make_timestamptz()
is a system function for assembling a timestamptz
value from the provided year, month, day, hour, minute, second and optionally the time zone.
make_timestamptz()
was added in PostgreSQL 9.4.
Usage
make_timestamptz (year
int
,month
int
,day
int
,hour
int
,min
int
,sec
double precision
[,timezone
text
] )
→ timestamp with time zone
All parameters must be provided.
An error is raised if any of the provided parameters is invalid.
Change history
- PostgreSQL 9.4
- added (commit 84df54b2)
Examples
Basic usage example for make_timestamptz()
:
postgres=# SELECT make_timestamptz(2021,8,29,23,10,56.32); make_timestamptz --------------------------- 2021-08-29 23:10:56.32+01 (1 row)
Providing an explicit time zone:
postgres=# SELECT make_timestamptz(2020,12,1,4,55,56.32, 'JST'); make_timestamptz --------------------------- 2020-11-30 20:55:56.32+01 (1 row)
Providing one or more invalid date parameters:
postgres=# SELECT make_timestamptz(2021,13,29,23,10,11.22); ERROR: date field value out of range: 2021-13-29
Providing one or more invalid time parameters:
postgres=# SELECT make_timestamptz(2021,8,29,25,10,99.32); ERROR: time field value out of range: 25:10:99.32
Providing an invalid time zone parameter:
postgres=# SELECT make_timestamptz(2001,2,12,14,13,22.36, 'Moon/Clavius'); ERROR: time zone "Moon/Clavius" not recognized
References
- PostgreSQL documentation: Date/Time Functions