Title: differenceBetweenDays() with Business Calendar returning unexpected values for inclusive leave calculation

Hi Team,

I am working on a POC on leave management requirement in Pega and using the below function to calculate the number of business days between two dates:

@differenceBetweenDays(.EndDate, .StartDate, true, “TestingCal”)

My requirement is to calculate leave duration as follows:

Start Date End Date PTO Type Expected Total Days
15-Jul-2026 15-Jul-2026 Full Day 1
15-Jul-2026 15-Jul-2026 Half Day 0.5
15-Jul-2026 17-Jul-2026 Full Day 3
15-Jul-2026 17-Jul-2026 Half Day 1.5

Currently this function is Returning as below

Start Date End Date PTO Type Expected Total Days Current Function Result
15-Jul-2026 15-Jul-2026 Full Day 1 0
15-Jul-2026 15-Jul-2026 Half Day 0.5 0
15-Jul-2026 20-Jul-2026 Full Day 4 3
15-Jul-2026 17-Jul-2026 Full Day 3 2

As per above observation I tried adding +1 to the function result but still few scenarios are failing
EX: Start Date =15th July 2026 and End Date is 18th July 2026 then Expected Output is “3”(15,16,17 dates as 18th is a Saturday) but output setting as 4 as we are adding +1 to the function output.

Kindly provide a suggestion if you have seen such issue with this function or else kindly provide any alternative function to fix this.

Thank you in advance. :slight_smile:

@VemulapudiB17750633 The business calendars only support full day “closed” days. For more granular leave management, especially if it’s on operator level, my instinct is that you would benefit from working more with data instances tailored to your needs.

@LantzAndreas Thank you for the response.
Problem here is not only with half days even with Full days
This function is not returning correct value for Full days too..
Please find below for better understanding

Start Date End Date PTO Type Expected Total Days Current Function Result
15-Jul-2026 15-Jul-2026 Full Day 1 0
15-Jul-2026 20-Jul-2026 Full Day 4 3
15-Jul-2026 17-Jul-2026 Full Day 3 2

Also
As per above observation I tried adding +1 to the function result but still few scenarios are failing
EX: Start Date =15th July 2026 and End Date is 18th July 2026 then Expected Output is “3”(15,16,17 dates as 18th is a Saturday) but output setting as 4 as we are adding +1 to the function output.

Solution Implemented

Since the business calendar functions i mentioned were not returning the expected inclusive business-day count for all leave scenarios, I implemented a custom Activity-based solution.

Approach:

  1. Calculate the total number of days in the selected date range, including both business and non-business days, using:

(EndDate - StartDate) + 1
Also, Initialize a parameter, Param.CurrentDate, with the value of the Start Date.

  1. Use a For Loop in an Activity to iterate through each day in the calculated date range.

  2. During each iteration:

    • Check whether Param.CurrentDate is a valid business day using the business calendar function:

@BusinessCalendar.isBusinessDay(Param.CurrentDate, “TestingCal”)

  • If the date is a business day, increment the business-day counter:

Param.Count = Param.Count + 1

  • Advance the current date by one day using:

@BusinessCalendar.addDays(Param.CurrentDate, 1, false, “TestingCal”)

  1. Continue the loop until all dates in the range have been evaluated.

  2. After the loop completes, set the accumulated business-day count to the Total Days property.

This approach evaluates each date individually against the configured business calendar, correctly excludes weekends and holidays, and provides the expected leave duration across all tested scenarios.