0 Replies Latest reply: Sep 8, 2014 4:10 AM by Oliver Graf RSS

    Working Days - Calculation Problem

    Oliver Graf

      I've got a problem with the correct calculatoin of working days between 2 dates.

       

      I like to calculate the working days between create-close stamp, as follows:

      create-stamp               close-stamp               Working days:

      12.08.2014                    19.08.2014                    -1

      11.08.2014                    18.08.2014                    -1

      11.08.2014                    18.08.2014                    -1

      ...

       

      Problem: The calculation for this period is not correct. Most of the other calculated values are right. But not in ther August-periode. What is the error ?

       

       

      Working_Days

       

      WorkingDays_ComputeWorkingDaysInRange(startdate+1; enddate+1)

       

      WorkingDays_ComputeWorkingDaysInRange

      If (_WorkingDays_IsValidDateRangeForWorkingDays(startdate; enddate);  _WorkingDays_ComputeNormalWorkingDaysInRange(startdate; enddate) - _WorkingDays_ComputeDaysOffInRange(startdate; enddate);  1/0

       

      Days_IsValidDateRangeForWorkingDays

      If (enddate < startdate;  1; If (startdate < _WorkingDays_FirstValidDateForWorkingDays() .Or. startdate > _WorkingDays_LastValidDateForWorkingDays();0;

      If (enddate > _WorkingDays_LastValidDateForWorkingDays()+1;0; 1 )))

       

      _WorkingDays_ComputeNormalWorkingDaysInRange

      ( _WorkingDays_IsWorkingDay(1) * CountOccurrencesOfWeekdayInRange(1; startdate; enddate)+ _WorkingDays_IsWorkingDay(2) * CountOccurrencesOfWeekdayInRange(2; startdate; enddate)+ _WorkingDays_IsWorkingDay(3) * CountOccurrencesOfWeekdayInRange(3; startdate; enddate)+ _WorkingDays_IsWorkingDay(4) * CountOccurrencesOfWeekdayInRange(4; startdate; enddate)+ _WorkingDays_IsWorkingDay(5) * CountOccurrencesOfWeekdayInRange(5; startdate; enddate)+ _WorkingDays_IsWorkingDay(6) * CountOccurrencesOfWeekdayInRange(6; startdate; enddate)+ _WorkingDays_IsWorkingDay(7) * CountOccurrencesOfWeekdayInRange(7; startdate; enddate))

       

      _WorkingDays_IsWorkingDay

      If (weekday .In.(2;3;4;5;6); 1; 0)

       

      CountOccurrencesOfWeekdayInRange

      If (weekday < 1 .Or. weekday > 7 .Or. enddate < startdate;  0; If (enddate = startdate;

      If (Weekday(startdate) = weekday; 1; 0); Age(startdate; enddate; 3) + Weekday_Is_In_Partial_Week(weekday; Weekday(startdate); Weekday(enddate))  ))

       

       

      _WorkingDays_DateIsWorkingDayInRange

      _WorkingDays_IsWorkingDay(Weekday(date)) * DateIsInRange(date; startdate; enddate)

       

      Weekday_Is_In_Partial_Week

      If (startday <= endday; If (weekday >= startday .And. weekday < endday; 1; 0); If (weekday >= startday .Or. weekday < endday; 1; 0))

       

      DateIsInRange

      If (enddate < startdate;   0; If (enddate = startdate;  If (date = startdate; 1; 0); If (startdate <= date .And. date < enddate; 1; 0)))

       

       

      _WorkingDays_ComputeDaysOffInRange

      /* Compute the number of days off in the given range of dates. *//* NOTE: Adjust the list below to account for your particular holidays, vacation days, etc. Be sure to also adjust the functions FirstValidDateForWorkingDays and LastValidDateForWorkingDays. */(/* 2014 */  _WorkingDays_DateIsWorkingDayInRange({2014-01-01}; startdate; enddate) /* Neujahr */+ _WorkingDays_DateIsWorkingDayInRange({2014-01-06}; startdate; enddate) /* Heilige Drei Könige*/+ _WorkingDays_DateIsWorkingDayInRange({2014-04-18}; startdate; enddate) /* Karfreitag*/+ _WorkingDays_DateIsWorkingDayInRange({2014-04-21}; startdate; enddate) /* Ostermontag */+ _WorkingDays_DateIsWorkingDayInRange({2014-05-01}; startdate; enddate) /* Maifeiertag */+ _WorkingDays_DateIsWorkingDayInRange({2014-05-29}; startdate; enddate) /* Christi Himmelfahrt */+ _WorkingDays_DateIsWorkingDayInRange({2014-06-09}; startdate; enddate) /* Pfingstmontag */+ _WorkingDays_DateIsWorkingDayInRange({2014-06-19}; startdate; enddate) /* Fronleichnam */+ _WorkingDays_DateIsWorkingDayInRange({2014-08-15}; startdate; enddate) /* Mariä Himmelfahrt */+ _WorkingDays_DateIsWorkingDayInRange({2014-10-03}; startdate; enddate) /* Tag der Deutschen Einheit*/+ _WorkingDays_DateIsWorkingDayInRange({2014-11-01}; startdate; enddate) /* Allerheiligen*/+ _WorkingDays_DateIsWorkingDayInRange({2014-12-25}; startdate; enddate) /* 1. Weihnachtstag*/+ _WorkingDays_DateIsWorkingDayInRange({2014-12-26}; startdate; enddate) /* 2. Weihnachtstag *//* 2015 */+ _WorkingDays_DateIsWorkingDayInRange({2015-01-01}; startdate; enddate) /* Neujahr */+ _WorkingDays_DateIsWorkingDayInRange({2015-01-06}; startdate; enddate) /* Heilige Drei Könige*/+ _WorkingDays_DateIsWorkingDayInRange({2015-04-03}; startdate; enddate) /* Karfreitag*/+ _WorkingDays_DateIsWorkingDayInRange({2015-04-06}; startdate; enddate) /* Ostermontag */+ _WorkingDays_DateIsWorkingDayInRange({2015-05-01}; startdate; enddate) /* Maifeiertag */+ _WorkingDays_DateIsWorkingDayInRange({2015-05-14}; startdate; enddate) /* Christi Himmelfahrt */+ _WorkingDays_DateIsWorkingDayInRange({2015-05-25}; startdate; enddate) /* Pfingstmontag */+ _WorkingDays_DateIsWorkingDayInRange({2015-06-04}; startdate; enddate) /* Fronleichnam */+ _WorkingDays_DateIsWorkingDayInRange({2015-08-15}; startdate; enddate) /* Mariä Himmelfahrt */+ _WorkingDays_DateIsWorkingDayInRange({2015-10-03}; startdate; enddate) /* Tag der Deutschen Einheit*/+ _WorkingDays_DateIsWorkingDayInRange({2015-11-01}; startdate; enddate) /* Allerheiligen*/+ _WorkingDays_DateIsWorkingDayInRange({2015-12-25}; startdate; enddate) /* 1. Weihnachtstag*/+ _WorkingDays_DateIsWorkingDayInRange({2015-12-26}; startdate; enddate) /* 2. Weihnachtstag *//* 2016 */+ _WorkingDays_DateIsWorkingDayInRange({2016-01-01}; startdate; enddate) /* Neujahr */+ _WorkingDays_DateIsWorkingDayInRange({2016-01-06}; startdate; enddate) /* Heilige Drei Könige*/+ _WorkingDays_DateIsWorkingDayInRange({2016-03-25}; startdate; enddate) /* Karfreitag*/+ _WorkingDays_DateIsWorkingDayInRange({2016-03-28}; startdate; enddate) /* Ostermontag */+ _WorkingDays_DateIsWorkingDayInRange({2016-05-01}; startdate; enddate) /* Maifeiertag */+ _WorkingDays_DateIsWorkingDayInRange({2016-05-05}; startdate; enddate) /* Christi Himmelfahrt */+ _WorkingDays_DateIsWorkingDayInRange({2016-05-16}; startdate; enddate) /* Pfingstmontag */+ _WorkingDays_DateIsWorkingDayInRange({2016-05-26}; startdate; enddate) /* Fronleichnam */+ _WorkingDays_DateIsWorkingDayInRange({2016-08-15}; startdate; enddate) /* Mariä Himmelfahrt */+ _WorkingDays_DateIsWorkingDayInRange({2016-10-03}; startdate; enddate) /* Tag der Deutschen Einheit*/+ _WorkingDays_DateIsWorkingDayInRange({2016-11-01}; startdate; enddate) /* Allerheiligen*/+ _WorkingDays_DateIsWorkingDayInRange({2016-12-25}; startdate; enddate) /* 1. Weihnachtstag*/+ _WorkingDays_DateIsWorkingDayInRange({2016-12-26}; startdate; enddate) /* 2. Weihnachtstag *//* 2017 */+ _WorkingDays_DateIsWorkingDayInRange({2017-01-01}; startdate; enddate) /* Neujahr */+ _WorkingDays_DateIsWorkingDayInRange({2017-01-06}; startdate; enddate) /* Heilige Drei Könige*/+ _WorkingDays_DateIsWorkingDayInRange({2017-04-14}; startdate; enddate) /* Karfreitag*/+ _WorkingDays_DateIsWorkingDayInRange({2017-04-17}; startdate; enddate) /* Ostermontag */+ _WorkingDays_DateIsWorkingDayInRange({2017-05-01}; startdate; enddate) /* Maifeiertag */+ _WorkingDays_DateIsWorkingDayInRange({2017-05-25}; startdate; enddate) /* Christi Himmelfahrt */+ _WorkingDays_DateIsWorkingDayInRange({2017-06-05}; startdate; enddate) /* Pfingstmontag */+ _WorkingDays_DateIsWorkingDayInRange({2017-06-15}; startdate; enddate) /* Fronleichnam */+ _WorkingDays_DateIsWorkingDayInRange({2017-08-15}; startdate; enddate) /* Mariä Himmelfahrt */+ _WorkingDays_DateIsWorkingDayInRange({2017-10-03}; startdate; enddate) /* Tag der Deutschen Einheit*/+ _WorkingDays_DateIsWorkingDayInRange({2017-11-01}; startdate; enddate) /* Allerheiligen*/+ _WorkingDays_DateIsWorkingDayInRange({2017-12-25}; startdate; enddate) /* 1. Weihnachtstag*/+ _WorkingDays_DateIsWorkingDayInRange({2017-12-26}; startdate; enddate) /* 2. Weihnachtstag */)