我有一个像2014-08-17T06:16:55.967Z
这样的时间戳,我想在Postgres中插入它,但是我想只删除毫秒,保留'T‘和'Z’。有人知道怎么可能吗?我试过2014-08-17T06:16:55.967Z::timestamp(0)
或timestamptz(0)
,但他们都拿走了我想要的东西。
我想要2014-08-17T06:16:55Z
。
发布于 2014-08-18 20:28:14
date_trunc
select date_trunc('second', '2014-08-17T06:16:55.967Z'::timestamp);
date_trunc
---------------------
2014-08-17 06:16:55
http://www.postgresql.org/docs/current/static/functions-datetime.html#FUNCTIONS-DATETIME-TRUNC
输入字符串中的T
和Z
没有保存在时间戳列中。如果要显示它们,则将输出格式化。
select to_char(
date_trunc('second', '2014-08-17T06:16:55.967Z'::timestamp),
'YYYY-MM-DD"T"HH24:MI:SSZ'
);
to_char
----------------------
2014-08-17T06:16:55Z
http://www.postgresql.org/docs/current/static/functions-formatting.html
https://stackoverflow.com/questions/25371281
复制相似问题