Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 23A58476778 for ; Fri, 22 Nov 2002 11:26:29 -0500 (EST) Received: from beamish.nsd.ca (unknown [205.150.156.194]) by postgresql.org (Postfix) with ESMTP id 6D75A476695 for ; Fri, 22 Nov 2002 11:26:08 -0500 (EST) Received: (from smap@localhost) by beamish.nsd.ca (8.9.3/8.9.3) id LAA03119; Fri, 22 Nov 2002 11:25:55 -0500 X-Authentication-Warning: beamish.nsd.ca: smap set sender to using -f Received: from reddog.nsd.ca(192.168.101.30) by beamish.nsd.ca via smap (V2.1/2.1+anti-relay+anti-spam) id xma003117; Fri, 22 Nov 02 11:25:36 -0500 Received: from nsd.ca (jllachan-linux.nsd.ca [192.168.101.148]) by reddog.nsd.ca (8.8.7/8.8.7) with ESMTP id LAA07455; Fri, 22 Nov 2002 11:24:35 -0500 Message-ID: <3DDE5AB1.84D805C0@nsd.ca> Date: Fri, 22 Nov 2002 11:26:25 -0500 From: Jean-Luc Lachance X-Mailer: Mozilla 4.77 [en] (X11; U; Linux 2.4.9-31 i686) X-Accept-Language: en MIME-Version: 1.0 To: Dan Langille Cc: praveen vejandla , pgsql-sql@postgresql.org Subject: Re: calculating interval References: <20021122092748.X3909-100000@m20.unixathome.org> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200211/346 X-Sequence-Number: 10488 Watch out! 36.85 weeks could have 37 sundays... Take into account the day of the week of the first and last day. Also, process the first and last day separately and work with whole day, if you want to exclude part of the day. Dan Langille wrote: > > 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. > > ---------------------------(end of broadcast)--------------------------- > TIP 6: Have you searched our list archives? > > http://archives.postgresql.org