PostGreSql Tips 2
USE OF FUNCTION EPOCH
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-08');
Result: 982384720 --secoonds till 2001-02-16 20:38:40-08 from 1970-01-01 00:00:00-00
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
Result: 442800 --seconds in interval 5 days 3 hours
Here is how you can convert an epoch value back to a time stamp:
SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 982384720 * INTERVAL '1 second';
USE OF FUNCTION EPOCH
SELECT EXTRACT(EPOCH FROM TIMESTAMP WITH TIME ZONE '2001-02-16 20:38:40-08');
Result: 982384720 --secoonds till 2001-02-16 20:38:40-08 from 1970-01-01 00:00:00-00
SELECT EXTRACT(EPOCH FROM INTERVAL '5 days 3 hours');
Result: 442800 --seconds in interval 5 days 3 hours
Here is how you can convert an epoch value back to a time stamp:
SELECT TIMESTAMP WITH TIME ZONE 'epoch' + 982384720 * INTERVAL '1 second';
Comments