You need to sign in to do that
Don't have an account?
Apex logic to calculate no. of business days between two date-time fields (not date fields)
HI,
I need apex logic to calculate no.of business days between two date-time fields. I have seen so many posts but everyone are mentioning only workflow logic but not apex logic.. (Assume Mon to Fri are business days)
Thanks in advance..
I need apex logic to calculate no.of business days between two date-time fields. I have seen so many posts but everyone are mentioning only workflow logic but not apex logic.. (Assume Mon to Fri are business days)
Thanks in advance..
Here, my requirement is to plugin the logic in controller, so I am looking for apex logic.
PS: Your formula gives only the no of days, not business days.
Checked the link, that would not give business days..
I had a similar requirement recently so I'll share my solution.
Refer to this link: https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_businesshours.htm#apex_System_BusinessHours_diff
First, you can create a BusinessHours object. Here, you can set what your business days/hours are. Once you have that, you can use the
method which will return to you the total number of Business hours that have elapsed between two DateTime objects. If I'm not mistaken this method returns the value in miliseconds, which you can then convert to days.
P.S.
Don't convert milliseconds to days using 24hrs, you'd do the conversion with whatever length each business day is according to you business hours object.