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 a list view on the holidays SMO which will permit you to manage your holidays.

3. Create an item view which will contain the controls in the image belowWorking Date Item View

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

NOTE: The _WeekEndOrNot rule contains advance condition which tests the value returned by the expression below (i). But If the expression returns a Saturday OR Sunday then we conclude that its 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 dayname, image below

Calculate Week Day Expression

5. Write an expression Ex_DayCounter image below. It increments each time we add a date and we store its value in dl_ActiveDayCounter.
Increment Woeking Day                                                        

6. When btn_GetWorkingDate clicked:Get Working Date

In 1, we initialise dl_ActiveWorkingDays to 1 then we store the date in Cldr_Date in dl_GivenDate. In 2, 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:Date value

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).Working Day Rules K2

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.

Working Day Rules K2 Details

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.

Thanks Guys!


Leave a Reply

Your email address will not be published. Required fields are marked *