Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Date() + 3
Message
From
21/07/2005 23:25:56
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
21/07/2005 22:58:35
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
01034976
Message ID:
01034980
Views:
16
>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 && Saturday
  	tdResult = tdResult + 1
  endif
  if dow(tdResult) = 1 && Sunday
  	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)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform