如何更改其他语言的PostgreSQL时间戳格式

时间:2018-07-24 11:17:53

标签: postgresql timestamp diff subtraction

PostgreSQL时间戳:

begin= '2018-06-07 08:29:49'
end  = '2018-06-10 04:07:57'

查询:

select sa.\"end\"::timestamp(0) - sa.begin::timestamp(0)
from tabelle sa;

输出:

  

2天19:38:08

我想将“ days”的输出更改为“ Tage”,例如:

  

2 Tage 19:38:08

最重要的是,当月份不同时,它应该在“ Monate”中显示月份,而对于“ Jahre”来说,年份也是如此。

我试图查看dateformat,但是我需要更改expr格式,而不是'%Y%m%d ...等格式。

我也尝试过:

to_char(extract(year from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Jahre '||to_char(extract(month from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Monate '||to_char(extract(day from (sa."end"::timestamp - sa.begin::timestamp)),'00')||' Tage '||to_char(extract(hour from (sa."end"::timestamp - sa.begin::timestamp)),'00')||':'||to_char(extract(minute from (sa."end"::timestamp - sa.begin::timestamp)),'00')||':'||to_char(extract(second from (sa."end"::timestamp - sa.begin::timestamp)),'00')

输出:

  

00 Jahre 00 Monate 02 Tage 19:38:08

它看起来不太好,因为如果有数字,应该显示月份或年份。

重要的是,只需要在“ Tage”中更改此“ day”,而不设置字符UFT8或其他德语语言内容!!!

请帮助我。

1 个答案:

答案 0 :(得分:0)

有一些解决方案,但以其他方式:

select extract(day from (sa.\"end\"::timestamp - sa.begin::timestamp))||' Tage '||
       to_char(extract(hour from (sa.\"end\"::timestamp-sa.begin::timestamp)),'00')||':'||
       to_char(extract(minute from (sa.\"end\"::timestamp - sa.begin::timestamp)),'00')||':'||
       to_char(extract(second from (sa.\"end\"::timestamp - sa.begin::timestamp)),'00')
       from tabelle sa

输出:

  

2 Tage 19:38:08

相关问题