We have a formula field that will calculate the number of days (excluding weekends) between two Date/Time fields.
Please find the formula below
ROUND(24*((5*FLOOR((DATEVALUE(First_Response__c)-DATE(1900,01,01))/7) + MIN(5,MOD(DATEVALUE(First_Response__c)-DATE(1900,01,01), 7) + MIN(1, (MOD(First_Response__c -DATETIMEVALUE('1900-01-01 00:00:00'), 1))) )) - (5*FLOOR((DATEVALUE(CreatedDate)-DATE(1900,01,01))/7) + MIN(5, MOD(DATEVALUE(CreatedDate)-DATE(1900,01,01), 7) + MIN(1, (MOD(CreatedDate-DATETIMEVALUE('1900-01-01 00:00:00'), 1))) )) ),2)
Please find the image that has the negative value
BusinessHours
into your calculation,Apex
is the correct approach.