Find the next working day, ignoring holidays and weekends

Hello everyone, I have a question about find the next working days(Lunch Delivery Dates
), I have source Data with Requested Delivery Date and Number of Day.
To add the Number of Day and find the Next the working days called(Lunch Delivery Dates ). after adding the number of days check new Lunch Delivery Date weekend or Holiday list , ignore the Date and Find the next Working Day.

Attached Source and Holiday master
WorkingDateCal.xlsx (1.3 MB)

Not sure I understand. What does “Number of Day” mean? What does it get added to? Also, what country do you want holidays for? It would be helpful if you could provide a small example of the expected output.

Hi, SG Holiday list included in source file

attachment take "Requested Delivery Date " and Shift the Date (Add Number of Days).after adding we will get to know that Lunch Delivery Dates ,then calculated the Lunch Delivery Dates and check if they fall on weekends or holidays, and adjust them to the find the next working day

Your data set has no delivery dates on holidays so its impossible to test on holidays. I can create a data set including holidays but I think that’s really up to you.
Here’s a workflow that handles weekends:
Lunch Delivery Dates.knwf (1.1 MB)

1 Like

Hi rfeigel, Thanks for your help. it’s give me some idea to continue to work.

My request is after shift the Number of Days in Requested Delivery Date The calculated the new Lunch Delivery Dates fall on holidays list, We needs to find the next working day Lunch Delivery Dates .

I have Updated with Valid Data Source and Holiday master as well

Example :
**When Requested Delivery Date is Apr 30-2025,
Lunch Delivery Dates= 30–Apr-2025 + 3 (Shift working day)+Ignore Holidays = 07-05-2025
image
For example,

May 1 Thur - DC works on Thur, but it’s holiday → non-working day

May 2 Fri - DC works on Fri, and it’s not holiday → working day

May 3 Sat - DC ** not works on Sat, though it’s not holiday → non-working day

May 4 Sun - DC not works on Sun, and it’s holiday → non-working day

May 5 Mon - DC works on Mon, but it’s holiday → non-working day

May 6 Tue - DC works on Tue, and it’s not holiday → working day

May 7 Wed - DC works on Wed, and it’s ** not holiday → working day {}
WorkingDateCal_1.xlsx (10.4 KB)

Hi @ravishing1984 , if you create a table that consists of a concatenation of all weekends and all your holidays you can calculate the required date using a recursive loop.

  • From your requested dates list, calculate your initial lunch delivery date.

  • Feed this list into the recursive loop start.

  • Add a joiner node to recursive loop start that joins lunch delivery date to holiday/weekend dates

  • Configure the joiner collect both left unmatched (lunch delivery dates that didn’t match to a holiday/weekend date) and matched, and split results to different output ports

  • Pass the left unmatched output to the topmost (collector) port of a recursive loop end node

  • Pass the matched output of the joiner to a Date&Time shift and add 1 day to each entry in the Lunch Delivery Date column, replacing that column.

  • The output of the Date&Time shift goes to the lower (recursion) port of the Recursive Loop End.

If you do the above and run it, the resultant output from the loop should be the required set of dates.

here is a demo

4 Likes

Your latest data set makes less sense than the first one. Can you provide data with clear Requested Delivery Date and holiday overlaps?

Thank you. was looking for this kind of solution for latest knime version

Thanks for you great help …attached workflow giving my above example 06-05-2025 output but Expected May 7 Wed - DC works on Wed…can i Know reason or my understating wrong

Hi @ravishing1984 ,

I’m not sure if you meant to actually attach a workflow (you said one was attached), as well as the screenshot, but the reason why the workflow I gave will return 06-05-2025 is because that was the requirement as you originally specified it and I didn’t see the subtle modification that you subsequently posted:

You originally said to:

  • add the requested number of days to the date
    (i.e. 2025-04-30 + 3 days = 2025-05-05)

  • find the next working day (taking into account holidays and weekends)

What I realise now that you subsequently clarified in your worked example is that you also need to take into account holidays and weekends when adding the days at the beginning, because you are adding working days and not just adding days

Try this, which hopefully addresses that issue by now adding the days 1 at a time within the loop rather than timeshifting prior to the loop. For each row it keeps a record of the number of days that remain to be added, and only subtracts 1 from this count if the date is a working day. When the count of days to add gets to 0, the chosen date is returned by the loop.

Here is v2 on the hub. I left the original so that the two approaches can be compared:


Yes, your understanding correct
01-05-2025 also Thu (Holiday) list ,We need to skip 01-05-2025 also Thu (Holiday)…In this case expected output 07-05-2025

2 Likes

Thanks for confirming, @ravishing1984 . Hopefully the above (v2) workflow addresses this correctly. Please let me know if it works for you.

2 Likes

Here is an alternate way of looking at the same issue. While I love recursion for its seemingly magical abilities, troubleshooting recursive loops is not always fun.

I tried to take a more straightforward approach:

  1. Identify all potential upcoming dates. I added 1000, but +365 might be better suited for your needs.
  2. Remove all weekends and holidays from the list of dates.
  3. Lag the date column to find previous valid date.
  4. Submit proposed dates to a binner node to find the valid date range/bin.

SAM_FindNextWorkingDay.knwf (681.3 KB)

Nice idea @jweiner. Your idea got me thinking about a potentially even simpler solution that doesn’t require loops, binners or lag columns :wink:

If we build the calendar of available dates at the beginning (by creating the entire set of dates and then removing from it all weekends and holidays) the resultant list can be interrogated with Value Lookup to find the first date on, or after a required date. So a Value Lookup to find the available date after the request date, and a subsequent Value Lookup to find “n days” after that will return the required date. Unlike the joiner node, the important feature of Value Lookup used here is that it can find the “next highest” date, if our initially chosen date is not in the calendar.

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.