Re: help on to_date conversion please....

From: Chris Pesko <cpesko(at)organic(dot)com>
To: pgsql-admin(at)postgresql(dot)org
Subject: Re: help on to_date conversion please....
Date: 2002-04-03 23:42:32
Message-ID: 4.3.2.7.2.20020403153945.00bb2030@mailhost.organic.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin

Never mind. Just figured it out. Need to grab the substring from 2 for 8
from the to_char result because it holds character number 1 reserv ed for +
or - signs. + is default or white space. I think that is the reason. Any
other input?????

hwds=# select to_date(substring(to_char(20020101, '99999999') from 2 for
8), 'yyyymmdd');
to_date
------------
2002-01-01
(1 row)

At 03:13 PM 4/3/02 -0800, Chris Pesko wrote:
>I am converting an 8 digit number to a date. I don't see a postgres
>function to do it direct, but two functions seems like I'm on the right
>track, to_char and to_date. Individually I get them to work, but when I
>combine them I get the wrong answer. see below. Can anyone help in
>getting the right date from an 8 digit number input formatted as yyyymmdd?
>
>
>hwds=# select to_char(20020101, '99999999');
> to_char
>-----------
> 20020101 CORRECT.
>(1 row)
>
>hwds=# select to_date('20020101','yyyymmdd');
> to_date
>------------
> 2002-01-01 CORRECT.
>(1 row)
>
>hwds=# select to_date(to_char(20020101, '99999999'),'yyyymmdd');
> to_date
>------------
> 2003-08-12 WHY DOES IT GIVE ME DIFFERENT ANSWER WHEN I COMBINE THE
> FUNCTIONS?
>(1 row)
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: subscribe and unsubscribe commands go to majordomo(at)postgresql(dot)org

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Stephan Szabo 2002-04-03 23:47:48 Re: help on to_date conversion please....
Previous Message Chris Pesko 2002-04-03 23:13:29 help on to_date conversion please....