Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate days to advance and skip weekend
Message
From
07/12/2017 11:06:21
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01656173
Message ID:
01656208
Views:
44
>>>>>
>>>>>I will try your approach. Although I don't like it ;) I have been thinking about it all day and you come up with a very simple formula :) Thank you!
>>>>
>>>>Assuming it works ;)
>>>>
>>>>My view? I think that sometimes we have to put some distance to a problem to get it solved. That is, sometimes what helps me is to stop thinking about a problem...
>>>
>>>I agree with you. My best solutions are either in my sleep or while I am taking a walk.
>>
>>Hum. I think it's better, now.
>>
>>
>>m.RealDaysToAdvance = m.DaysToAdvance + INT((m.TodayDow + m.DaysToAdvance - 1) / 5) * 2
>>
>>
>>And a small program to give us a visual clue.
>>
>>
>>LOCAL DaysToAdvance AS Integer
>>LOCAL RealDaysToAdvance AS Integer
>>LOCAL Advanced AS Integer
>>LOCAL DisplayDays AS Integer
>>
>>CLEAR
>>
>>LOCAL TodayDow AS Integer
>>
>>m.TodayDow = 1
>>
>>FOR m.DaysToAdvance = 1 TO 20
>>
>>	? m.DaysToAdvance
>>
>>	m.RealDaysToAdvance = m.DaysToAdvance + INT((m.TodayDow + m.DaysToAdvance - 1) / 5) * 2
>>
>>	?? " - >", m.RealDaysToAdvance
>>	? "."
>>
>>	m.Advanced = 0
>>
>>	FOR m.DisplayDays = 1 TO m.RealDaysToAdvance
>>
>>		IF (m.TodayDow + m.DisplayDays) % 7 = 6 OR (m.TodayDow + m.DisplayDays) % 7 = 0
>>			?? "|"
>>		ELSE
>>			?? "+"
>>			m.Advanced = m.Advanced + 1
>>		ENDIF
>>
>>	ENDFOR
>>
>>	?? "", m.Advanced
>>
>>ENDFOR
>>
>
>I am trying your approach. I don't quite understand the resulting "image" your code creates though.
>
>But I was thinking last night, after I turned off the computer. Maybe there is a simpler way to do what I need to do. Let me describe what this code is suppose to do. The code sets the Target Date based on the Current Date and the Days2Advance (the number of days that should be given for the job). Some customers consider Saturday non working day and therefore, skip it. Others consider Sunday a non working day and skip it. And then others consider both Saturday and Sunday as non working days.
>I could simply create a loop and advance the date from current date, adding 1 day in the loop (until Days2Advance is reached). And in the loop, on every advance check the Day of the Week and if it is Saturday/Sunday, do not add it to the Days2Advance.
>
>But I am still curious how your formula works but I will change the code to real dates and create to FOR: one iterating the Today's day, say from Jan 1, 2017 to March 1, 2017. Then, within this FOR I will change the DaysToAdvance from 1 to 20 (very reasonable range). And then, using your formula, calculate the Target/End date. And if it is NOT Saturday or Sunday, the formula works. Does it make sense?
>
>UPDATE: Unfortunately when I run my code with real dates, many ending dates fall on either Saturday or Sunday. Don't waste your time on my problem. I will try the LOOP approach that I described above.
>Thank you very much!

Hi, Dmitry.

The visualization code loops through different DaysToAdvance just to demonstrate that the calculation of real days to advance (this is just one line of code) is getting a pair of extra days for each weekend it encounters (that is, trying with 1 day to advance, then with 2, and so on). In the visual list, the dot is the starting day, each + represents a business day that was advanced, and each | a weekend day (Sat. or Sun.). So, each iteration must end with a + (that is, a business day), and in my runs that occurs no matter which DaysToAdvance, and no matter which TodayDow (from 1 to 5).

Can you give an example of a situation for a real date for which some advance of days falls on the weekend? Don't worry, it's an academic interest... What is important is that you have a working solution (I think that going through a loop is a sensible solution, considering your full requirements and also the questions that Dragan pointed out).
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform