Post Reply 
Casio FC-200 Financial Consultant
12-26-2020, 11:31 PM (This post was last modified: 12-27-2020 05:17 AM by Albert Chan.)
Post: #11
RE: Casio FC-200 Financial Consultant
We can make the code more compact, with sign function.

PHP Code:
function sign(x) return x==and or x/abs(xend

function networkdays(AB)      -- assumed date A <= B
    local W 
A%7               -- weekday(A)
    if 
W==0 then W=1A=A+1 end -- A Sun -> Mon
    local D 
B-A
    local E 
floor(D/7)        -- weeks
    
return D-E-sign(D-7*6)    
end 

Update: the code had a bug, when A falls on Sunday.
Shifting it to Monday fixed it, matched open-office networkdays() results.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Casio FC-200 Financial Consultant - Gamo - 12-15-2020, 12:07 PM
RE: Casio FC-200 Financial Consultant - Albert Chan - 12-26-2020 11:31 PM



User(s) browsing this thread: 1 Guest(s)