Received: from mta1-rme.xtra.co.nz (mta1-rme.xtra.co.nz [203.96.92.1]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f262Eox83799 for ; Mon, 5 Mar 2001 21:14:51 -0500 (EST) (envelope-from csawtell@xtra.co.nz) Received: from berty ([210.55.121.65]) by mta1-rme.xtra.co.nz with SMTP id <20010306021610.WUPL2261674.mta1-rme.xtra.co.nz@berty>; Tue, 6 Mar 2001 15:16:10 +1300 Content-Type: text/plain; charset="iso-8859-1" From: Christopher Sawtell Organization: At Home To: , pgsql-sql@postgresql.org Subject: Re: count number of weeks?? Date: Tue, 6 Mar 2001 15:14:59 +1300 X-Mailer: KMail [version 1.2] References: <20010305175516.18950.qmail@nwcst315.netaddress.usa.net> In-Reply-To: <20010305175516.18950.qmail@nwcst315.netaddress.usa.net> MIME-Version: 1.0 Message-Id: <01030615145900.11327@berty> Content-Transfer-Encoding: 8bit X-Archive-Number: 200103/82 X-Sequence-Number: 1730 On Tue, 06 Mar 2001 06:55, rocael@usa.net wrote: > Hi all! > I wonder how in PG7.0.2 I can count the number of weeks from a date > field that I have in a table, lets say: > > table trial has in its fields start_date as sysdate(), and now I want to > do a select that will give me the number of weeks from now [sysdate()] > to the start_date. chris=# select (select date('3 May 2001')-date(CURRENT_TIMESTAMP))::float8 / 7.0 as "Weeks Till Start"; Weeks Till Start ------------------ 8.28571428571429 (1 row) chris=# select (select date('3 May 2001') - date(CURRENT_TIMESTAMP))::int / 7 as "Weeks Till Start"; Weeks Till Start ------------------ 8 (1 row) chris=# select version(); version ------------------------------------------------------------------------ PostgreSQL 7.1beta5 on i586-pc-linux-gnu, compiled by GCC egcs-2.91.66 (1 row) That the sort of thing you wanted? Don't know if it will work in 7.0.3, but upgrading is just a doddle. PostgreSQL compiles faultlessly. -- Sincerely etc., NAME Christopher Sawtell CELL PHONE 021 257 4451 ICQ UIN 45863470 EMAIL csawtell @ xtra . co . nz CNOTES ftp://ftp.funet.fi/pub/languages/C/tutorials/sawtell_C.tar.gz -->> Please refrain from using HTML or WORD attachments in e-mails to me <<--