Re: Extract date from a TIMESTAMP(6) WITHOUT TIME ZONE NOT NULL column

From: John R Pierce <pierce(at)hogranch(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Extract date from a TIMESTAMP(6) WITHOUT TIME ZONE NOT NULL column
Date: 2016-09-22 04:14:42
Message-ID: 84eafdcf-1635-917d-c120-397101609b55@hogranch.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 9/21/2016 8:37 PM, Patrick B wrote:
> I'm using postgres 9.2 and got the following column:
>
> start TIMESTAMP(6) WITHOUT TIME ZONE NOT NULL
>
>
> SELECT start FROM test1;
>
>
> 2015-12-18 02:40:00
>
> I need to split that date into two columns on my select:
>
> 2015-12-18 = date column
> 02:40:00 = time column

select start::date as date_column start::time as time_column from ....

BUT, you really gotta watch out for type conversions around timestamp
WITHOUT time zone, as most conversions expect TIMESTAMP WITH TIME ZONE,
which internally are stored in UTC but are converted from/to
CLIENT_TIMEZONE on input output. so timestamp without time zone can get
converted to timestamp with time zone, then converted to date or time,
and get all messed up.

--
john r pierce, recycling bits in santa cruz

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Ian Campbell 2016-09-22 05:59:12 Re: Unstable C Function
Previous Message Adrian Klaver 2016-09-22 04:08:27 Re: Extract date from a TIMESTAMP(6) WITHOUT TIME ZONE NOT NULL column