Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate days to advance and skip weekend
Message
 
 
To
07/12/2017 12:01:13
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01656173
Message ID:
01656212
Views:
37
>>>
>>>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).
>>
>>This is the code I used to apply your formula:
>>
>>I starting with the first day of this year and scan 40 days. Then scan through up to 20 advance days. If the resulting date falls on Saturday or Sunday, show the message. Let me know if you see anything I missed.
>>
>>dStartDate = CTOD('12/31/2016')
>>FOR i = 1 TO 40
>>	dStartDate = dStartDate + i
>>	
>>	FOR nDays2Advance = 1 TO 20 
>>		m.TodayDow = DOW(dStartDate)
>>		m.RealDaysToAdvance = m.nDays2Advance + INT((m.TodayDow + m.nDays2Advance - 1) / 5) * 2	
>>		dEndDate = dStartDate + m.RealDaysToAdvance
>>		IF DOW(dEndDate) = 1 OR DOW(dEndDate) = 7
>>			MESSAGEBOX("Wrong day. " + " Start Date: " + DTOC(dStartDate) + ;
>>			" Days to Advance " + ALLTRIM(STR(m.nDays2Advance)) + "  Real days to advance: " + ALLTRIM(STR(m.RealDaysToAdvance)) + CHR(13) + ;
>>			"End Date: " + DTOC(dEndDate) + " which is " + ALLTRIM(STR(DOW(dEndDate))))
>>                ENDIF
>>	ENDFOR 
>>
>>ENDFOR 
>>
>
>The formula uses a convention where 1 = Monday, 6 and 7 are weekend days. So, if you change to m.TodayDow = DOW(dStartDate, 2), the advanced days won't fall on a weekend (you can leave the test as it is, that is, for the test you can use the convention 1 = Sunday, it's irrelevant).

I missed that. Thank you for the explanation.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform