X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 462A053485 for ; Tue, 19 Apr 2005 11:37:08 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 03462-03 for ; Tue, 19 Apr 2005 14:37:03 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 39FA6534AC for ; Tue, 19 Apr 2005 11:37:01 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j3JEb6Mg021422; Tue, 19 Apr 2005 10:37:06 -0400 (EDT) To: "Jeff Eckermann" Cc: pgsql-sql@postgresql.org Subject: Re: DateAdd function ? In-reply-to: References: Comments: In-reply-to "Jeff Eckermann" message dated "Tue, 19 Apr 2005 09:23:30 -0500" Date: Tue, 19 Apr 2005 10:37:06 -0400 Message-ID: <21421.1113921426@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.007 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200504/291 X-Sequence-Number: 21184 "Jeff Eckermann" writes: > There is no "dateadd" function in PostgreSQL, but you can write your own > easily enough. The following should give you an idea of the logic you can > use: > jeck=# select current_date + cast('1 day' as interval); Alternatively, maybe you want to use the date-plus/minus-integer operators. regression=# select current_date; date ------------ 2005-04-19 (1 row) regression=# select current_date + 1; ?column? ------------ 2005-04-20 (1 row) regression=# select current_date - 1; ?column? ------------ 2005-04-18 (1 row) There isn't really a date-plus-interval operator --- what's happening there is the date is implicitly promoted to timestamp and then timestamp-plus-interval is used. You might want this if you want to add symbolic quantities like '2 months' or '1 year', but for small integer numbers of days, the integer operations are faster and simpler to use. regards, tom lane