|Subject||Re: [firebird-support] working days between two dates|
|Author||Svein Erling Tysvær|
>Hi Tomas! I just mean week days...I don't know whether this is common or not (can't remember anyone asking for it before on this list), but if you don't care about special days it could be implemented as simple as this:
>Something like DateDiff() but only counting from monday to friday.
>I have a function in Delphi for that. I could make an UDF I think. I just wander if there is something already done. I thought it was something "very used"... probably is not?
execute block (fromdate date = :fromdate, todate date = :todate) returns (weekdays integer) as
declare variable checkdate date;
weekdays = 0;
checkdate = fromdate;
while (checkdate <= todate) do
if (checkdate < todate - 6) then
weekdays = weekdays + 5;
checkdate = checkdate + 7;
if (extract(weekday from checkdate) between 1 and 5) then
weekdays = weekdays + 1;
checkdate = checkdate + 1;
There should be other ways to do this in Firebird as well (some of them better), this is just one way that quickly comes to mind.