Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 62058475AE4 for ; Fri, 22 Nov 2002 09:36:15 -0500 (EST) Received: from m20.unixathome.org (m20.unixathome.org [66.11.168.227]) by postgresql.org (Postfix) with ESMTP id 0F946475461 for ; Fri, 22 Nov 2002 09:36:14 -0500 (EST) Received: by m20.unixathome.org (Postfix, from userid 1001) id 259D87A1C; Fri, 22 Nov 2002 09:36:15 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by m20.unixathome.org (Postfix) with ESMTP id 20BD41E8E; Fri, 22 Nov 2002 09:36:15 -0500 (EST) Date: Fri, 22 Nov 2002 09:36:15 -0500 (EST) From: Dan Langille X-X-Sender: dan@m20.unixathome.org To: praveen vejandla Cc: pgsql-sql@postgresql.org Subject: Re: calculating interval In-Reply-To: <20021122142609.11784.qmail@webmail31.rediffmail.com> Message-ID: <20021122092748.X3909-100000@m20.unixathome.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/344 X-Sequence-Number: 10486 On 22 Nov 2002, praveen vejandla wrote: > Dear All, > > Is there any way in postgresql to calculate the interval between > two times excluding specific days,specific duration. > > Ex: > timestamp1 : 2002-10-01 10:30AM > timestamp2 : 2002-15-01 04:50PM > > suppose if i need the difference between timestamp1,timestamp2 but > i don't want to count how many sun days are coming, i want to > ignore all sundays in between,i want to ignore certain timings(say > 10.00 AM to 5:00PM)s also,then how can I get the duration in this > way. My guess: write a function. Calculating the number of days between the two dates is easy. To avoid certain days, of the week, in your case, Sunday, I would count the number of whole weeks between the two dates. test=# select '2002-10-01 10:30AM'::timestamp - '2002-15-01 04:50PM'::timestamp; ?column? ---------------- 258 days 16:40 In this case 258/7 = 36.85... So you know you have 36 Sundays in there. This will need adjusting for non-full weeks. Hope that gets you started.