X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 89AB8D1E15D for ; Fri, 20 Feb 2004 20:26:48 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 32986-04 for ; Fri, 20 Feb 2004 16:26:34 -0400 (AST) Received: from mail-s03.websys.aol.com (mail-s03.websys.aol.com [64.12.180.167]) by svr1.postgresql.org (Postfix) with ESMTP id 959DDD1E0D2 for ; Fri, 20 Feb 2004 16:26:31 -0400 (AST) Received: from inf-s24.websys.aol.com (inf-s24.websys.aol.com [172.20.116.86]) by mail-s03.websys.aol.com (8.12.10/8.12.9) with ESMTP id i1KKQKUq008055; Fri, 20 Feb 2004 15:26:20 -0500 (EST) Received: from aol.net (dhcp178-176-34.office.aol.com [10.178.176.34]) by inf-s24.websys.aol.com (8.12.10/8.12.9) with ESMTP id i1KKQE9c003284; Fri, 20 Feb 2004 15:26:14 -0500 (EST) Message-ID: <40366D40.4030405@aol.net> Date: Fri, 20 Feb 2004 15:25:36 -0500 From: Brian Knox User-Agent: Mozilla Thunderbird 0.5 (X11/20040209) X-Accept-Language: en-us, en MIME-Version: 1.0 To: "scott.marlowe" Cc: pgsql-sql@postgresql.org Subject: Re: Date Foo. References: In-Reply-To: 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: 200402/313 X-Sequence-Number: 17003 Sorry, Not looking for a way to extract a month from a timestamp. I'm looking for a way to convert an interval from days to months. I'm not sure after digging into it that there is a way to handle it in SQL, as the interval that results from subtracting one timestamp from another is not away of what months the interval spans, so there'd be no proper way to take month lengths into account. I gave up on the sql and used Date::Calc from Perl. Thanks for your answer anyway. scott.marlowe wrote: > On Thu, 19 Feb 2004, Brian Knox wrote: > > >>( sorry if this is a repeat, my mail server is being wonky today ) >> >>I'm looking for a way, within SQL, given a starting date and an ending >>date, to get back the number of months between the start and end date. >>If I "SELECT end_date - start_date", I get back an interval in days; I >>need months. > > > Maybe date_part? > > select date_part('month','2004-08-02 12:00:00'::timestamp) - > date_part('month','2004-05-01 12:00:00'::timestamp); >