[英]Convert seconds to yyyy-mm-dd hh:mm:ss PostgreSQL
I am new to PostgreSQL sql and now working on an already existing database.我是 PostgreSQL sql 的新手,现在正在处理一个已经存在的数据库。 I have a column called value in a table and it contains datetime stamp in seconds.我在表中有一个名为 value 的列,它包含以秒为单位的日期时间戳。 So I am looking for way I can convert those seconds to yyyy-mm-dd hh:mm:ss in a Postgres database.所以我正在寻找可以在 Postgres 数据库中将这些秒数转换为 yyyy-mm-dd hh:mm:ss 的方法。 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: 1444646136079 是我想转换的值但我收到以下错误:
ERROR: interval field value out of range: "1444646136079 second"错误:间隔字段值超出范围:“1444646136079 秒”
An interval
is not a "timestamp". interval
不是“时间戳”。
The to_timestamp()
function accepts seconds as an input and can convert that to a proper timestamp. to_timestamp()
函数接受秒作为输入,并且可以将其转换为适当的时间戳。 I believe your 1444646136079 is in fact milli seconds, not seconds:我相信你的 1444646136079 实际上是毫秒,而不是秒:
select to_char(to_timestamp(1444646136079 / 1000), 'yyyy-mm-dd HH24:MI:SS')
returns:返回:
2015-10-12 12:35:36
You can try it too -你也可以试试——
select to_date(to_timestamp(1344646136069 / 1000)::TEXT, 'yyyy-mm-dd HH24:MI:SS');
select to_date(to_timestamp(1344646136069 / 1000)::TEXT, 'YYYY-MM-DD HH:MI:SS');
Output :输出:
11.08.2012 00:00:00
11.08.2012 00:00:00
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.