postgresqlHow do I set a timestamp in PostgreSQL?
PostgreSQL provides two timestamp data types: timestamp
and timestamptz
.
The timestamp
data type stores the date and time information without any timezone information. The timestamptz
data type stores the date and time information including the timezone information.
To set a timestamp in PostgreSQL, you can use the to_timestamp
function.
For example, to set a timestamp
with the value 2020-07-14 12:00:00
:
SELECT to_timestamp('2020-07-14 12:00:00', 'YYYY-MM-DD HH24:MI:SS');
Output example
2020-07-14 12:00:00
To set a timestamptz
with the value 2020-07-14 12:00:00
:
SELECT to_timestamp('2020-07-14 12:00:00', 'YYYY-MM-DD HH24:MI:SS')::timestamptz;
Output example
2020-07-14 12:00:00+00
The to_timestamp
function takes two parameters:
- The timestamp value in
YYYY-MM-DD HH24:MI:SS
format. - The format of the timestamp value.
For more information, please refer to the PostgreSQL documentation.
More of Postgresql
- How can I use PostgreSQL XOR to compare two values?
- How can Zalando use PostgreSQL to improve its software development?
- How can I troubleshoot zero damaged pages in PostgreSQL?
- How can I use PostgreSQL's "zero if null" feature?
- How do I use PostgreSQL ZonedDateTime to store date and time information?
- How do I use PostgreSQL's XMLTABLE to parse XML data?
- How can I retrieve data from PostgreSQL for yesterday's date?
- How do I parse XML data using PostgreSQL?
- How can I use PostgreSQL with YAML?
- How can I monitor PostgreSQL performance using Zabbix?
See more codes...