X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0D29B47592C for ; Sun, 2 Feb 2003 12:38:24 -0500 (EST) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by postgresql.org (Postfix) with ESMTP id 866254758DC for ; Sun, 2 Feb 2003 12:38:22 -0500 (EST) Received: from klaster.net (pc135.krakow.cvx.ppp.tpnet.pl [213.76.38.135]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id C3EC22B6F7; Sun, 2 Feb 2003 18:32:11 +0100 (CET) Message-ID: <3E3D5800.50103@klaster.net> Date: Sun, 02 Feb 2003 18:40:16 +0100 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; PL; rv:1.1) Gecko/20020826 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: "joe.guyot" Cc: pgsql-sql@postgresql.org Subject: Re: how do i create a date from a substring??? References: <20030131154041.19708.qmail@web20101.mail.yahoo.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/36 X-Sequence-Number: 11434 joe.guyot wrote: > greetings all! > > [i just became a member] > > i have a string data from a view that is a packed field. it > contains a date, a time and a user's initials. i'm trying to extract > the date portion in a pg 7 view. the data originally came from a ms > sql 7 table that has since been converted into a pg 7 table. > > in the ms sql 7 view the date was extracted as follows: > > convert(timestamp, substring(creat, 1, 8), 120) = 'createdate' > > where creat is the packed field from the original table and > 'createdate' is the extracted date portion. the data would typically > look like: 200111171623XYX. the result is '2001-11-17'. > > i've reviewed documentation, on line books and several threads in > this and related newsgroups and can't seem to come up with a decent > solution. > > i've tried various combinations of this in a pg 7 view: > > to_date(substr(creat,1,8),'YYYY-MM-DD') = 'createdate' > to_date(substring(creat from 1 for 8),'YYYY-MM-DD') = > 'createdate' > to_timestamp(substr(creat,1,8),'YYYY-MM-DD') = 'createdate' > to_timestamp(substrsting(creat from 1 for 8),'YYYY-MM-DD') = > 'createdate' > > and continually get different errors: > "bad date external representation 'createdate'" > or > "bad timestamp external representation 'createdate'" Your substring-date isn't in 'YYYY-MM-DD' format, but in 'YYYYMMDD' Regards, Tomasz Myrta