shg_sistemas wrote:
Using FB 2.5 is there an easy way to get the workings days between to dates? Or should I do an UDF for that?
Svein Erling Tysvær answers:
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:
execute block (fromdate date = :fromdate, todate date = :todate)
returns (weekdays integer) as
declare variable checkdate date;
begin
weekdays = 0;
checkdate = fromdate;
while (checkdate <= todate) do
begin
if (checkdate < todate - 6) then
begin
weekdays = weekdays + 5;
checkdate = checkdate + 7;
end
else
begin
if (extract(weekday from checkdate) between 1 and 5) then
weekdays = weekdays + 1;
checkdate = checkdate + 1;
end
end
suspend;
end
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.