Re: Query with time zone offset but without seconds

From: Adrian Klaver <adrian(dot)klaver(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Cc: Marco <netuse(at)lavabit(dot)com>
Subject: Re: Query with time zone offset but without seconds
Date: 2011-03-25 21:21:15
Message-ID: 201103251421.17266.adrian.klaver@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(dot)klaver(at)gmail(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jake Stride 2011-03-25 22:18:50 Using data for column names in plpgsql
Previous Message Merlin Moncure 2011-03-25 20:21:30 Re: Deadlock in libpq