SmokeEater
Technical User
I have been trying to get this formula to work but I can't get it to maintain the number of holidays that is calculated when the year changes. Here is the code.
PS. I tracked down most of the coding thanks to Tek-Tips.
PS. I tracked down most of the coding thanks to Tek-Tips.
Code:
//Main formula
WhileReadingRecords;
Local DateVar Start := Minimum({?MyDate}); //{StartDate}; // place your Starting Date here
Local DateVar End := Maximum({?MyDate}); //{EndDate}; // place your Ending Date here
Local NumberVar Weeks;
Local NumberVar Days;
Local Numbervar Hol;
DateVar Array Holidays;
Weeks:= (Truncate (End - dayofWeek(End) + 1 - (Start - dayofWeek(Start) + 1)) /7 ) * 5;
Days := DayOfWeek(End) - DayOfWeek(Start) + 1 +
(if DayOfWeek(Start) = 1 then -1 else 0) +
(if DayOfWeek(End) = 7 then -1 else 0);
//Holiday Calculation
numberVar yr := Year ({polegs.locsched}); // The year for which you need Holidays
redim Holidays [12];
holidays [1] := CDate (yr, 1, 1); // New Years day
holidays [2] := {@GoodFridayHoliday}; // Good Friday
holidays [3] := holidays [2]+3; // Easter Monday
holidays [4] := CDate (DateAdd ("d", 25 - DayOfWeek (CDate (yr, 5, 11), crMonday), CDate (yr, 5, 1) ) );
// Victoria Day (4th Mon in May)
holidays [5] := CDate (yr, 7, 1); // July 1 (Canada Day)
holidays [6] := CDate (DateAdd ("d", 8 - DayOfWeek (CDate (yr, 8, 1) , crMonday), CDate (yr, 8, 1) ) );
// Civic Holiday (first Mon in Aug)
holidays [7] := CDate (DateAdd ("d", 7 - DayOfWeek (CDate (yr, 9, 1) , crTuesday), CDate (yr, 9, 1) ) );
// Labor Day (first Mon in Sept)
holidays [8] := CDate (DateAdd ("d", 15 - DayOfWeek (CDate (yr, 10,1), crMonday), CDate (yr, 10,1) ) );
// Thanksgiving (2nd Mon. in Oct)
holidays [9] := CDate (yr, 11, 11); // Armistice Day
holidays [10] := CDate (yr, 12, 25); // Merry Christmas
holidays [11] := CDate (yr, 12, 26); // Boxing Day
Local NumberVar i;
For i := 1 to Count (Holidays)
do (if Holidays[i] in start to end then Hol:=Hol+1 );
Weeks + Days - Hol