Count number of workdays between 2 columns

Hi,

I need help with my workflow. I am trying to figure out how to count the number of workdays between two columns with specific. Example: column A date is July 31, 2023, column B is August 25, 2023. How will I be able to get the number of weekdays between the 2 dates?

Thanks in advance for your help.

You can convert both columns into Date&Time columns and then calculate the difference between the two. This will only give you calendar days, though. Workdays are not a well-defined because there can local, regional, or country-wide holidays, for example.

If you are targeting a simpler Monday - Friday calc, then I would start with the “Extract Date&Time Fields” node. You can get the Day of week number, and Year (week based) along with several others. You should be able to use a formula using those 2 fields to calculate the number of week days in a range.

It would be a cool advanced setting addition to the Date&Time Difference node to be able to define which days of the week should be used in a calculation.

@jepavila This is fairly crude but it works. Hope you can adapt it for your use.

1 Like

Hi @jepavila
alternatively you could script it with python node
similar to that adjusted for knime in and output tables

import pandas as pd

def count_weekdays(start_date, end_date):
    date_range = pd.date_range(start=start_date, end=end_date)
    weekdays = date_range.weekday < 5  # 0 to 4 represent Monday to Friday
    return weekdays.sum()

# Assuming you already have a DataFrame named 'df'
df['Weekdays'] = df.apply(lambda row: count_weekdays(row['start date'], row['end date']), axis=1)


br

1 Like

Hi,

You might get started with this component: Dias habiles entre dos fechas (con calendario de festivos) – KNIME Community Hub

Best

1 Like

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