X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 31878D1B501 for ; Wed, 17 Sep 2003 20:25:18 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 96635-01 for ; Wed, 17 Sep 2003 17:24:46 -0300 (ADT) Received: from serwer.skawsoft.com.pl (serwer.skawsoft.com.pl [213.25.37.66]) by svr1.postgresql.org (Postfix) with ESMTP id C4D5CD1B502 for ; Wed, 17 Sep 2003 17:24:43 -0300 (ADT) Received: from klaster.net (core-1.citynet.pl [80.48.135.69]) by serwer.skawsoft.com.pl (Postfix) with ESMTP id 794D32B3D7; Wed, 17 Sep 2003 22:24:10 +0200 (CEST) Message-ID: <3F68C302.9020602@klaster.net> Date: Wed, 17 Sep 2003 22:24:34 +0200 From: Tomasz Myrta User-Agent: Mozilla/5.0 (Windows; U; Win 9x 4.90; pl-PL; rv:1.5a) Gecko/20030718 X-Accept-Language: pl, en-us, en MIME-Version: 1.0 To: wireless Cc: pgsql-sql@postgresql.org Subject: Re: how to get decimal to date form References: <90446ee7.0309170450.2f16d9ef@posting.google.com> In-Reply-To: <90446ee7.0309170450.2f16d9ef@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200309/167 X-Sequence-Number: 15145 > In our postgre database is a decimal field with format YYMMDDhhmmss.9999999999 > where the 9s are random digits. I'm trying to strip off just the > YYMMDD and put it in date form. > > So far I came up with: > SUBSTR(TO_CHAR(rec_num,99999999999),1,6) AS Date which returns YMMDD. > > For example where the rec_num is 30608124143.47069519725 the above > functions return 30608. > > I tried wrapping another TO_CHAR around it to try to format it to a > date but this seems like it's a bit much for this purpose. > > Any suggestions would be appreciated. > > -David 1. replace 0 with 9 to get leading zeroes - 030608 instead of 30608 2. to_date('030608','YYMMDD'); Regards, Tomasz Myrta