Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 76E2663291E for ; Tue, 13 Jul 2010 12:02:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 45271-01 for ; Tue, 13 Jul 2010 15:02:21 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by mail.postgresql.org (Postfix) with ESMTP id A7A84632DD7 for ; Tue, 13 Jul 2010 12:02:20 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id o6DF2APD029027; Tue, 13 Jul 2010 11:02:10 -0400 (EDT) To: "Campbell, Lance" cc: pgsql-sql@postgresql.org Subject: Re: subtract two dates to get the number of days In-reply-to: References: Comments: In-reply-to "Campbell, Lance" message dated "Tue, 13 Jul 2010 09:58:53 -0500" Date: Tue, 13 Jul 2010 11:02:10 -0400 Message-ID: <29026.1279033330@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.91 tagged_above=-5 required=5 tests=BAYES_00=-1.9, T_RP_MATCHES_RCVD=-0.01 X-Spam-Level: X-Archive-Number: 201007/58 X-Sequence-Number: 34371 "Campbell, Lance" writes: > I want to subtract to dates to know the number of days different. > Example: > 01/02/2010 - 01/01/2010 = 1 day > 08/01/2010 - 07/31/2010 = 1 day > How do I do this? If they're dates, you just subtract. regression=# select '08/01/2010'::date - '07/31/2010'::date; ?column? ---------- 1 (1 row) regards, tom lane