Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Calculate days to advance and skip weekend
Message
From
07/12/2017 12:01:13
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01656173
Message ID:
01656210
Views:
39
>>
>>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).
----------------------------------
António Tavares Lopes
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform