Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Compute vacation
Message
From
04/10/2004 08:28:16
Mike Yearwood
Toronto, Ontario, Canada
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00948387
Message ID:
00948427
Views:
14
Borislav

There have been many examples of code to compute number of weekdays.
*
*  WEEKDAYS.PRG
*  Return the number of days that are MONDAY - FRIDAY
*  in the passed date range.
*  Returns .F. if parameters are not passed properly.
*
*  USAGE:
*    ?WEEKDAYS({^2004-05-01},{^2004-05-31})
*
*  OR:
*    ldFrom = {^2004-05-01}
*    ldTo = {^2004-05-31}
*    luWeekdays = WEEKDAYS(m.ldFrom, m.ldTo)
*    IF m.luWeekdays = .F.
*      ?"Routine failed"
*     ELSE
*      ?"The number of weekdays was: " + ALLTRIM(STR(m.luWeekdays)) + "."
*    ENDIF
*
*  RETURNS:
*    A numeric value for the number of weekdays.
*    This also indicates the routine succeeded.
*    Returns .F. (false) when called with
*    incorrect parameters.
*
*  lParameters
*     tdFrom (R)     Start of the date range.
*     tdTo   (R)     End of the date range.
*
LPARAMETERS m.tdFrom, m.tdTo
*If called with incorrect parameters, RETURN .F.
IF NOT (VARTYPE(m.tdFrom)="D" AND VARTYPE(m.tdTo)="D")
  RETURN .F.
ENDIF

LOCAL ;
  m.lnDays, ;
  m.lnDOW

*Determine the total possible number of days.
m.lnDays = ABS(m.tdFrom - m.tdTo) + 1

*Determine the number of the day of the week.
m.lnDOW = DOW(MIN(m.tdFrom,m.tdTo),2)

*Subtract the weekend (Sat/Sun) days.
*Also remove the difference between the 
*"start" date and the closest Monday.
RETURN m.lnDays - INT(m.lnDays / 7) * 2 ;
	- IIF( m.lnDOW = 7, ;
	     SIGN(m.lnDays % 7), ;
	     SIGN(m.lnDOW - 7 + (m.lnDays % 7)) + 1)
>>hi all,
>>
>>if i want to take (21 or more or less) days as vication
>>how i can compute how many days i have ,without friday+saturdy days
>>
>>thisform.text1.value=startdate
>>thisform.text2.value=enddate
>>thisform.text3.value=thisform.text1.value-thisform.text1.value&&(without friday+saturdy days)
>>
>>thanks.
>
>Mohammed, the first think that comes to my mind is to wrote the function that calculate this:
>
>
>thisform.text1.value=startdate
>thisform.text2.value=enddate
>thisform.text3.value=CalculateDays(startdate, enddate)
>
>
>FUNCTION CalculateDays(startdate, enddate)
>  LOCAL cycle, tocycle, testdate, ret_val
>  ret_val = 0
>  tocycle = enddate-startdate
>  FOR cycle = 0 TO tocycle
>      testdate = startdate+cycle
>      IF .NOT. INLIST(DOW(ScanDay,1), 6, 7)  && friday, saturday
>         ret_val = ret_val + 1
>      ENDIF
>  ENDFOR
>
>RETURN ret_val
>
>
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform