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 3A20AD1E149 for ; Thu, 19 Feb 2004 21:59:03 +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 31873-09 for ; Thu, 19 Feb 2004 17:59:03 -0400 (AST) Received: from mail1.ihs.com (mail1.ihs.com [170.207.70.222]) by svr1.postgresql.org (Postfix) with ESMTP id 47F37D1E13C for ; Thu, 19 Feb 2004 17:59:01 -0400 (AST) Received: from css120.ihs.com (css120.ihs.com [170.207.105.120]) by mail1.ihs.com (8.12.10/8.12.10) with ESMTP id i1JLwH7k019883; Thu, 19 Feb 2004 14:58:17 -0700 (MST) Date: Thu, 19 Feb 2004 14:51:26 -0700 (MST) From: "scott.marlowe" To: Brian Knox Cc: Subject: Re: DISTINCT ON troubles In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-IHS-MailScanner: Found to be clean X-IHS-MailScanner-SpamCheck: X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200402/292 X-Sequence-Number: 16982 On Thu, 19 Feb 2004, 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); Note that I think you need a +1 at the end of that...