Skip site navigation (1) Skip section navigation (2)

Re: calculating interval

From: Jean-Luc Lachance <jllachan(at)nsd(dot)ca>
To: Dan Langille <dan(at)langille(dot)org>
Cc: praveen vejandla <praveen_vejandla(at)rediffmail(dot)com>,pgsql-sql(at)postgresql(dot)org
Subject: Re: calculating interval
Date: 2002-11-22 16:26:25
Message-ID: 3DDE5AB1.84D805C0@nsd.ca (view raw or flat)
Thread:
Lists: pgsql-sql
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

In response to

pgsql-sql by date

Next:From: Jeff BoesDate: 2002-11-22 18:34:57
Subject: Re: calculating interval
Previous:From: Tom LaneDate: 2002-11-22 15:10:42
Subject: Re: Date trunc in UTC

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group