Postgresql:epoch the use of new era time

Source: Internet
Author: User
Tags epoch time postgresql

Epoch time is based on 1970-01-01 00:00:00 UTC as standard time and will target time with 1970-01-01 00:00:00
The difference in time is calculated in seconds, in seconds, and can be negative values; Some applications store time in the Epoch time form to improve read efficiency,
The following shows the usage conversion method for the epoch time in pg.


--1 convert time stamp times to epoch time
Francs=> Select Extract (epoch from timestamp without time zone ' 1970-01-01 01:00:00 ');
Date_part
-----------
3600
(1 row)

Francs=> Select Extract (epoch from timestamp without time zone ' 1970-01-01 02:00:00 ');
Date_part
-----------
7200
(1 row)

Francs=> Select Extract (Epoch from interval ' +1 hours ');
Date_part
-----------
3600
(1 row)


Francs=> Select Extract (Epoch from interval '-1 hours ');
Date_part
-----------
-3600
(1 row)

--2 Convert epoch time to time stamp
Francs=> Select timestamp without time zone ' epoch ' + 3600 * interval ' 1 second ';
? column?
---------------------
1970-01-01 01:00:00
(1 row)

Francs=> Select timestamp without time zone ' epoch ' + 7200 * interval ' 1 second ';
? column?
---------------------
1970-01-01 02:00:00
(1 row)


The interpretation of the epoch in the--3 Handbook
For date and timestamp values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative);
For interval values, the total number of seconds in the interval

Epoch

For date and timestamp values, the number of seconds since 1970-01-01 00:00:00 UTC (can be negative); For interval values, the total number of seconds in the interval

SELECT EXTRACT (EPOCH from TIMESTAMP with time ZONE ' 2001-02-16 20:38:40.12-08 ');  982384720.12 SELECT EXTRACT (EPOCH from INTERVAL ' 5 days 3 hours ');442800

Here's how can I convert an epoch value back to a time stamp:

SELECT TIMESTAMP with Time ZONE ' epoch ' + 982384720.12 * INTERVAL ' 1 second ';

Http://www.postgresql.org/docs/9.1/static/functions-datetime.html

Postgresql:epoch the use of new era time

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.