function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
The new LearnerThe new Learner 

How to find out the business day between two dates using Apex class

Hi Experts, 

I want to find out the business day between two dates need to exclude holidays and weekends. Can anyone help me pls 
AnudeepAnudeep (Salesforce Developers) 
Hi,

You have to use BusinessHours to achieve this See https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_businesshours.htm

Try using the method isWithin(businessHoursId, targetDate) because Holidays are included in the calculation

Please refer https://salesforce.stackexchange.com/questions/155113/add-days-to-created-date-excluding-weekend-and-holidays for sample code

If this answers your question, please mark this as best answer so that it can help others in the community. Thank You!

Anudeep
The new LearnerThe new Learner
Hi anudeep, Thanks for the reply, my requirement is if start date is today and enddate is today-3,then I have to exclude holidays and weekends, I am struggling alot to achieve this can you help me pls