In the steps below, I show you how you calculate the next working day when we add a number of working days(B) to any date(A),  considering weekends and holidays(C) using K2.

Example: Calculate the next working date given 4 working days and the date (7/17/2019) considering that 7/23/2019 is a holiday.

Solution: We get as result  7/24/2019, image below.

### Realisation Steps

1. Create a Smartbox SMO which will keep all your holidays.

2. Generate an editable list view on the holidays SMO which will permit you to manage your holidays.

3. Create an item view that will contain the controls in the image below

4. Write  _WeekEndOrNot rule which tells if a given date is  weekend (Yes) or not (No), steps in image below:

NOTE: The _WeekEndOrNot rule contains an advance condition that tests the value returned by the expression below (i). But If the expression returns a Saturday OR Sunday then we conclude that it’s a weekend and transfer “Yes”  to dl_IsWeekEnd else we transfer a “No” to dl_IsWeekEnd.

i.  An expression that collects the date in dl_NextWorkingDate and returns the day name, image below

5. Write an expression Ex_DayCounter image below. It increments each time we add a date and we store its value in dl_ActiveDayCounter. This expression will be called in point 7 (Block II) subsection C.

6. When btn_GetWorkingDate clicked:

In 1, we validate controls A & BIn 2, we initialise dl_ActiveWorkingDays to 1 then we store the date found in Cldr_Date in dl_GivenDate. In 3, we execute Ex_AddDate and keep its value in dl_NextWorkingDate which calls the rule in point 7 below.

7. Next, we write the _DateValueChange rule that is structured as in the image:

From the image above,

Block: I. Checks if the date in dl_NextWorkingDate  is a holiday or weekend (dl_IsHoliday has a value Or dl_IsWeekEnd is equal to Yes).

In A we store the current value of dl_NextWorkingDate in “dl_GivenDate”.

B Permits to add 1 day to dl_NextWorkingDate which calls when dl_NextWorkingDate Changes(Loop) rule, until we get a working day.

II. Checks if dl_NextWorkingDate contains a working day and we have not added the number of days the user gave.

In C we update dl_ActiveDayCounter by passing to it Ex_DayCounter.

D Keep working date in dl_GivenDate.

E  Permits to add 1 day to dl_NextWorkingDate which calls when dl_NextWorkingDate Changes(Loop), till we get a working day.

III. Finally, we check if we have added all the days the user gave and if the actual date in dl_NextWorkingDate is a working day.