X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id B01DF4764FB for ; Fri, 31 Jan 2003 02:04:59 -0500 (EST) Received: from web20107.mail.yahoo.com (web20107.mail.yahoo.com [216.136.226.44]) by postgresql.org (Postfix) with SMTP id D626D4764EB for ; Fri, 31 Jan 2003 02:04:57 -0500 (EST) Message-ID: <20030131070343.62550.qmail@web20107.mail.yahoo.com> Received: from [67.118.164.180] by web20107.mail.yahoo.com via HTTP; Thu, 30 Jan 2003 23:03:43 PST Date: Thu, 30 Jan 2003 23:03:43 -0800 (PST) From: "joe.guyot" Subject: how can i convert a substring to a date? To: pgsql-sql@postgresql.org MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200302/23 X-Sequence-Number: 11422 greetings all! 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'" i'm sure this has an obvious solution but i can't seem to find it. any suggestions are appreciated. regards, yusuf __________________________________________________ Do you Yahoo!? Yahoo! Mail Plus - Powerful. Affordable. Sign up now. http://mailplus.yahoo.com