Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate days to advance and skip weekend
Message
From
08/12/2017 16:08:07
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01656173
Message ID:
01656221
Views:
46
>>>>Hi,
>>>>
>>>>I am writing the code in C# but if I know how to do it in VFP, I can easily convert it to C#. That is, I know C# but weak in math :). And I can do this with a bunch of IF CASE and so on. But I think there should be a more concise formula.
>>>>
>>>>nTodayDow - today/current day Day of the week (1 to 7)
>>>>nDays2Advance - variable that holds the number of days to advance, from the current day. This can be 1 to any reasonable number (e.g. 100). And I want to change the nDays2Advance given that the weekend should be skipped (Saturday and Sunday).
>>>>Example:
>>>>nTodayDow = 3 (Wednesday)
>>>>nDays2Advance = 2
>>>>So the nDays2Advance = 2 (since the weekend is too far ahead)
>>>>But if nDays2Advance is 4, then it should be changed to 6, otherwise it will fall on the weekend.
>>>>
>>>>How can I express the above in the formula that would help me calculate nDays2Advance?
>>>>
>>>>TIA
>>>
>>>Thank you everybody who took the time to help me with this problem. The solution I implemented is to set the infinite loop (in C# while {true}), then advancing the date one day at a time. And then checking if the resulting date is Saturday/Sunday; in which case skipping the date. Until reaching the nDays2Advance that does not fall on a weekend.
>>
>>And I came up with this years ago: http://fox.wikis.com/wc.dll?Wiki~Weekdays~Wiki
>>
>>A similar solution was posed recently by Pinal Dave for SQL Server.
>
>Thank you.

I saw that you asked for how to get Weekdays between two dates. I don't think that's what you really want. If you want to add 10 week days to 2017-12-08, then you could convert your 10 business days to weekdays and correct for beginning and/or ending on a weekend. 7 weekdays is 1.4 business days. So advance 14 days to the 22nd. If the beginning date is Saturday move your beginning ahead 2. If Sunday move it ahead 1. If the ending date is Sunday take off 1. If Saturday take off 2. So starting 2017-12-09 you'd change that to the 11th and then going 14 days from there to the 25th. Then if a holiday falls between the 2 dates and is not a weekend, subtract that.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform