On Feb 4, 2010, at 3:43 AM, Bert Groeneveld wrote:
I'm breaking my head about finding some "super algorythm" for this:
I want to correct AGE_INFO, by omitting the days of the weekend (saturday and sunday)
An interesting little math problem. I think this works ...
on workDaysOld(aDate)
set adjDate to date (date string of aDate)
set adjCurrDate to date (date string of (current date))
set actualDaysOld to ((adjCurrDate - adjDate) div days)
set weeksOld to (actualDaysOld div 7)
set remainingDays to (actualDaysOld mod 7) as integer
set todaysIndex to (weekday of adjCurrDate as integer)
todaysIndex - remainingDays
if the result < 1 then
set remainingDays to (remainingDays - 2)
else if the result = 1 then
set remainingDays to (remainingDays - 1)
end if
return ((5 * weeksOld) + remainingDays)
end workDaysOld
Test it and let us know.