Received: from mx99.openu.ac.il (arbel.openu.ac.il [147.233.32.4]) by hub.org (8.9.3/8.9.3) with ESMTP id MAA38370 for ; Sun, 1 Aug 1999 12:56:50 -0400 (EDT) (envelope-from herouth@oumail.openu.ac.il) Received: from talmon.openu.ac.il (talmon.openu.ac.il [147.233.32.11]) by mx99.openu.ac.il (Postfix) with ESMTP for id 3FF444B4FE; Sun, 1 Aug 1999 19:56:46 +0300 (IDT) Received: from [147.233.159.109] (mac-herouth.pc.openu.ac.il) by talmon.openu.ac.il (Netscape Messaging Server 3.54) with ESMTP id AAA485D; Sun, 1 Aug 1999 20:00:08 +0300 X-Sender: herouth@shaked.cc.openu.ac.il Message-Id: In-Reply-To: Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Date: Sun, 1 Aug 1999 19:57:36 +0300 To: Thomas Good , "PostgreSQL::SQL List" From: Herouth Maoz Subject: Re: [SQL] date_arithmetic revisited At 17:15 +0300 on 30/07/1999, Thomas Good wrote: > Is there a way/function that allows me to do simple date arithmetic, > ala, `SELECT $enddate - startdate;' ? Sure. Nike. I mean, just do it. What you get from it depends, of course, on the type of the fields. If they are of type date, you get the round number of days between them (the result is of type int4): testing=> select d_start, d_end, d_end - d_start from test2; d_start| d_end|?column? ----------+----------+-------- 01-15-1969|08-01-1999| 11155 07-14-1999|07-18-1999| 4 04-13-1998|03-12-1998| -32 12-01-1999|12-01-1999| 0 (4 rows) If they are of type datetime, you get a timespan describing the difference: testing=> select t_end - t_start as result from test1; result ---------------------- @ 11154 days 23 hours @ 4 days @ 31 days 23 hours ago @ 0 (4 rows) If this doesn't suit you, you can take the date_part( 'day', ... ) from the above operation, but it truncates rather than rounds. The result is float8, BTW. Herouth -- Herouth Maoz, Internet developer. Open University of Israel - Telem project http://telem.openu.ac.il/~herutma