Re: counting days

Поиск
Список
Период
Сортировка
От Ragnar
Тема Re: counting days
Дата
Msg-id 1156892227.5167.17.camel@localhost.localdomain
обсуждение исходный текст
Ответ на counting days  (garry saddington <garry@schoolteachers.co.uk>)
Список pgsql-general
On þri, 2006-08-29 at 19:35 +0100, 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.


how about something like:

# assuming d id number of days
# and dow is day of week of first day (0-7;sun=0)

wholeweeks=days div 7
partial=days mod 7

# adjust dow to mon=0,tue=1...sun=6
dow=(dow+6) mod 7

# count 5 weekdays for each whole week
wd=5*wholeweeks

# add all days of partial week
wd=wd+partial

# substract 1 if saturday was included
if dow+partial>=6 then wd=wd-1

# substract 1 if sunday was included
if dow+partial>=7 then wd=wd-1

# now wd is result


hope this helps
gnari



В списке pgsql-general по дате отправления:

Предыдущее
От: CSN
Дата:
Сообщение: Re: database files are incompatible with server, after computer restart
Следующее
От: Ron Johnson
Дата:
Сообщение: Re: strange sum behaviour