Caliculating Business Days and adding business days usefull functions for developers

Поиск
Список
Период
Сортировка
От bujjibabu
Тема Caliculating Business Days and adding business days usefull functions for developers
Дата
Msg-id 453289.75353.qm@web95213.mail.in2.yahoo.com
обсуждение исходный текст
Список pgsql-sql
<div style="font-family: Arial; font-size: 10pt; color: #000000"><style>p { margin: 0; }</style><div
style="font-family:Arial; font-size: 10pt; color: rgb(0, 0, 0);"><br />Hi, <br /><br />I want to contribute my small
amountof effort to the group.<br /><br />Please accept this and create a new thread for me, Developers might need these
functionsto fulfil their busineess needs.<br /><br />//create table holidays and insert records of public holidays.<br
/><br/>CREATE TABLE public.holidays ( <br />    holiday    date NULL <br />    )<br />WITHOUT OIDS <br />TABLESPACE
pg_default<br/>GO<br /><br /><br />select bizdays ( fromdate , todate )  will give actual working days<br /><br
/>//functiongives exact no.of working days between from and to date.<br /><br />CREATE OR REPLACE FUNCTION
public.bizdays(in date, in date) RETURNS int8 AS<br />$BODY$<br />  SELECT count(*) FROM <br />    (SELECT
extract('dow'FROM $1+x) AS dow<br />     FROM generate_series(0,$2-$1) x) AS foo<br />  WHERE dow BETWEEN 1 AND 5;<br
/>$BODY$<br/>LANGUAGE 'sql'<br />GO<br /><br /><br />select fromdate +calcbizdays ( startdate ,noofworkingdays,
counter) will get added to no.of.working days<br /><br /><br />//function gives exact no.of calendar days after
noofworkingdaysfrom startdate , input counter is always zero.<br /><br />CREATE OR REPLACE FUNCTION public.calcbizdays
(indate, in int4, in int4) RETURNS int4 AS<br />$BODY$DECLARE <br />currdate ALIAS FOR $1;<br />daystoadd ALIAS FOR
$2;<br/>coun ALIAS FOR $3;<br />BEGIN<br /><br />if (select (bizdays(currdate , <br />currdate+daystoadd+coun)-
count(*)-1)<br />from holidays where holiday between currdate <br />and  currdate+daystoadd+coun)=daystoadd then<br
/>returndaystoadd+coun;<br /><br />else<br />return addbizdays(currdate,daystoadd,coun+1);<br />end if;<br />RETURN
0;<br/>END;$BODY$<br />LANGUAGE 'plpgsql'<br />GO<br /><br />Thanks,<br />Malladi Bujji Babu<br /><br /><br
/></div></div><br/><hr size="1" /> The INTERNET now has a personality. YOURS! <a
href="http://in.rd.yahoo.com/tagline_yyi_1/*http://in.yahoo.com/"target="_blank">See your Yahoo! Homepage</a>. 

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: ORDB and dot-notation query
Следующее
От: Emi Lu
Дата:
Сообщение: Fuzzy match under PostgreSQL 8.0.15