Re: counting days

From: Ragnar <gnari(at)hive(dot)is>
To: AgentM <agentm(at)themactionfaction(dot)com>
Cc: PostgreSQL General ML <pgsql-general(at)postgresql(dot)org>
Subject: Re: counting days
Date: 2006-08-29 23:46:35
Message-ID: 1156895195.5167.20.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On þri, 2006-08-29 at 17:32 -0400, AgentM wrote:
> Perhaps you are trying to count business days? Those vary around the
> world and you would certainly need a table to hold the holidays and
> such. If you just want to count the number of non-weekend-days, then
> get the interval as days and then it's a simple matter of math:
>
> 2*daysInterval/7+(daysInterval % 7 == 6 ? 1 : 0)

looks like you are calculating the number of weekend
days here, not the number of weekdays. looks like you are assuming the
interval started on a monday, too.

gnari

> This holds assuming you are using dates and not timestamps- you may
> wish to subtract 1 depending on what the dates represent.
>
> -M
>
> On Aug 29, 2006, at 14:35 , garry saddington wrote:
>
> > I need to count the days between two dates that are not saturdays or
> > sundays. I have read the manual and searched the lists but I am
> > struggling. I can count the days but am finding difficulty
> > excluding sat
> > and sun from the count. I need this without reference to any tables.
> > Does anyone have any pointers please.
> > Regards
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/docs/faq
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Joshua D. Drake 2006-08-30 00:01:24 Re: strange sum behaviour
Previous Message David Fetter 2006-08-29 23:40:43 Re: counting days