Received: from mx1.organic.com (mx1.organic.com [207.76.139.5]) by postgresql.org (Postfix) with ESMTP id 853A9474E6D for ; Wed, 3 Apr 2002 18:38:34 -0500 (EST) Received: from vw-sf.organic.com (vw-sf.organic.com [207.76.139.10]) by mx1.organic.com (8.9.3+Sun/8.9.3) with SMTP id PAA25339 for ; Wed, 3 Apr 2002 15:38:21 -0800 (PST) Received: FROM fwd1-sf.organic.com BY vw-sf.organic.com ; Wed Apr 03 15:38:37 2002 -0800 Received: from goldengate.organic.com (goldengate.organic.com [192.168.5.47]) by fwd1-sf.organic.com (8.9.3+Sun/8.9.3) with ESMTP id PAA03783 for ; Wed, 3 Apr 2002 15:41:20 -0800 (PST) Received: from cpesko-del-sfo.organic.com (h28.n23.organic.com [192.168.23.28]) by goldengate.organic.com (8.9.3+Sun/8.9.3) with ESMTP id PAA24456 for ; Wed, 3 Apr 2002 15:38:56 -0800 (PST) Message-Id: <4.3.2.7.2.20020403153945.00bb2030@mailhost.organic.com> X-Sender: cpesko@mailhost.organic.com X-Mailer: QUALCOMM Windows Eudora Version 4.3.2 Date: Wed, 03 Apr 2002 15:42:32 -0800 To: pgsql-admin@postgresql.org From: Chris Pesko Subject: Re: help on to_date conversion please.... In-Reply-To: <4.3.2.7.2.20020403150804.0464e440@mailhost.organic.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Archive-Number: 200204/44 X-Sequence-Number: 3933 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@postgresql.org