Re: Query with time zone offset but without seconds

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: Query with time zone offset but without seconds
Дата
Msg-id 201103251421.17266.adrian.klaver@gmail.com
обсуждение исходный текст
Ответ на Query with time zone offset but without seconds  (Marco <netuse@lavabit.com>)
Список pgsql-general
On Friday, March 25, 2011 10:05:59 am Marco wrote:
> I have a column »timestamp with time zone«. I want to extract the date/time
> in a different format including the time zone offset in a query but
> without seconds. If I do
>
>   select to_char(datetime, 'YYYY-MM-DD HH24:MI') from table;
>
> then the time zone offset is missing in the output: 2011-03-25 18:01
> If I do
>
>   select date_trunc( 'minute', datetime) from table;
>
> then the time zone offset is present, but the seconds are not removed:
> 2011-03-25 18:01:00+01
>
> I want it to look like this: 2011-03-25 18:01+01
>
> How to do that?
>
>
> Marco

Maybe something like:

test(5432)aklaver=>SELECT * from timestamp_test ;
 id | txt_fld |            ts_fld             |        ts_fld2
----+---------+-------------------------------+------------------------
  1 | test1   | 2009-03-11 12:35:43.065678-07 | (NULL)
  3 | test3   | 2009-03-11 13:37:01.166354-07 | (NULL)
  2 | test2   | 2009-03-11 12:42:15.276405-07 | (NULL)
  4 | test3   | 2009-03-11 14:37:48.993075-07 | (NULL)
  5 | test3   | 2009-03-12 12:38:07.722856-07 | (NULL)
  6 | test4   | 2009-12-24 13:35:51.59005-08  | (NULL)
  7 | test4   | 2009-12-24 13:37:32.499764-08 | 2009-12-24 13:37:32-08
  8 | t       | 2010-05-20 08:13:28.157027-07 | 2010-05-20 12:13:28-07
  9 | t       | 2010-05-20 08:13:43.265383-07 | 2010-05-20 10:13:43-07
 10 | t       | 2010-05-20 08:13:53.718519-07 | 2010-05-20 13:13:54-07
 11 | s       | 2011-03-25 09:00:00.124-07    | 2011-03-25 14:15:13-07
 12 | s       | 2011-03-25 09:12:00.124-07    | 2011-03-25 14:16:27-07


test(5432)aklaver=>SELECT regexp_replace(date_trunc('minute',
ts_fld)::text,':00{1}','') from timestamp_test;
   regexp_replace
---------------------
 2009-03-11 12:35-07
 2009-03-11 13:37-07
 2009-03-11 12:42-07
 2009-03-11 14:37-07
 2009-03-12 12:38-07
 2009-12-24 13:35-08
 2009-12-24 13:37-08
 2010-05-20 08:13-07
 2010-05-20 08:13-07
 2010-05-20 08:13-07
 2011-03-25 09:00-07
 2011-03-25 09:12-07



--
Adrian Klaver
adrian.klaver@gmail.com

В списке pgsql-general по дате отправления:

Предыдущее
От: Merlin Moncure
Дата:
Сообщение: Re: Deadlock in libpq
Следующее
От: Marco
Дата:
Сообщение: Re: Query with time zone offset but without seconds