>Hi all,
>
>How to avoid Saturday and Sunday when used date() + 3 ?
>
>If it falls on both Saturday and Sunday that date() + 3 should skip next
>Monday .
>
>date() is Monday , date()+3 is Thursday OK
>date() is Tuesday, date()+3 is Friday OK
>date() is Wednesday, date()+3 is Saturday not OK
>date() is Wednesday, Date() + 3 + ??? shoul be next monday OK
>how to do this, please assist me in coding ?
And what day is 3 days from Friday - Monday, or do you want to count 3 working days up to Tuesday? I will assume the latter. It would be something like this:
function AddWorkingDays(tdDate, tnDays)
local i, tdResult
tdResult = tdDate
for i = 1 to tnDays
tdResult = tdResult + 1
if dow(tdResult) = 7
tdResult = tdResult + 1
endif
if dow(tdResult) = 1
tdResult = tdResult + 1
endif
next
return tdREsult
If you want to add hundreds or thousands of days, some optimizations would be convenient, for example, start dividing by seven (integer division) to see how many entire weeks you got - and multiply the number of weeks by 5 (5 working days a week).
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)