Re: Weekends between

From: Serge Fonville <serge(dot)fonville(at)gmail(dot)com>
To: Luiz Eduardo Cantanhede Neri <lecneri(at)gmail(dot)com>
Cc: postgresql novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Weekends between
Date: 2009-07-30 14:50:12
Message-ID: 680cbe0e0907300750s41e019f8pe94540160384daba@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

> I'm trying to find out how many weekends there's between 2 dates and
> Googling I found this algorithm from
> http://archives.postgresql.org/pgsql-sql/2002-06/msg00304.php
>
> date := now - day_of_the_week
>> interval := interval + day_of_the_week
>> date := date + int( interval/5)x7 + ( interval mod 5)
I'm no math wizz, but:
I'd guess you would need to know the amount of days between start and end date
How many full weeks there are in there
And then add the weekend days that are located at the ends
So end date minus (total days mod 7)
with that information you can add (if needed another weekend or day)

If anyone has something better, please, do correct me!

HTH

Regards,

Serge Fonville

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Jason Stelzel 2009-07-31 00:32:29 Re: Synchronizing the schema of two PostgreSQL databases
Previous Message Luiz Eduardo Cantanhede Neri 2009-07-30 14:40:01 Weekends between