HOW TO
In ArcGIS Pro, Python can be used to calculate the number of weekdays between two date fields, supporting temporal analysis that excludes weekends. This is useful for business workflows or tracking activities based on working days.
This article provides the workflow to calculate the number of weekdays between two date fields using Python in ArcGIS Pro.

count_weekdays(!<fieldName1>!,!<fieldName2>!)

from datetime import datetime, timedelta
def count_weekdays(<fieldName1>, <fieldName2>):
# Convert input to datetime if it's not already
if isinstance(<fieldName1>, str):
<fieldName1> = datetime.strptime(<fieldName1>, "%m/%d/%Y")
if isinstance(<fieldName2>, str):
<fieldName2> = datetime.strptime(<fieldName2>, "%m/%d/%Y")
# Initialize count
count = 0
current_date = <fieldName1>
while current_date <= <fieldName2>:
# Count only weekdays (Monday to Friday)
if current_date.weekday() < 5:
count += 1
current_date += timedelta(days=1)
return count
Below is the complete working script for this example.
from datetime import datetime, timedelta
def count_weekdays(start_date, end_date):
# Convert input to datetime if it's not already
if isinstance(start_date, str):
start_date = datetime.strptime(start_date, "%m/%d/%Y")
if isinstance(end_date, str):
end_date = datetime.strptime(end_date, "%m/%d/%Y")
# Initialize count
count = 0
current_date = start_date
while current_date <= end_date:
# Count only weekdays (Monday to Friday)
if current_date.weekday() < 5:
count += 1
current_date += timedelta(days=1)
return count
The attribute table below displays the calculated number of weekdays in the new field in ArcGIS Pro.

Article ID: 000034784
Get help from ArcGIS experts
Start chatting now