I am new to PostgreSQL sql and now working on an already existing database. I have a column called value in a table and it contains datetime stamp in seconds. So I am looking for way I can convert those seconds to yyyy-mm-dd hh:mm:ss in a Postgres database. I tried the following:
SELECT TO_CHAR('1444646136079 second'::interval, 'yyyy-mm-dd HH24:MI:SS')
1444646136079 is the value I would like to convert But I am getting the following error:
ERROR: interval field value out of range: "1444646136079 second"
An interval
is not a "timestamp".
The to_timestamp()
function accepts seconds as an input and can convert that to a proper timestamp. I believe your 1444646136079 is in fact milli seconds, not seconds:
select to_char(to_timestamp(1444646136079 / 1000), 'yyyy-mm-dd HH24:MI:SS')
returns:
2015-10-12 12:35:36
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With