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
sebastian lonbergsebastian lonberg 

time to resolve a case

In Salesforce I have to date/time fields: -ClosedDate -CreatedDate in the Case object.
I have another field which is a formula field(number) names TimeToClose, and I want that field to contain in hours the time since CreatedDate to ClosedDate , only summing the business hours and week days. for example:
Date/Time Opened 4/3/2023, 9:56 AM
Date/Time Closed 4/3/2023, 2:11 PM
in thiis case the answer should be something near 4 hours.
I tried this but for the mentioned Case , the output is showing -0.63 and it does not have sense.
Thank you so much for any help.
Best Answer chosen by sebastian lonberg
SubratSubrat (Salesforce Developers) 
Hello Sabastian ,

You can try with below formula and let me know further :
 
IF(
  NOT(ISBLANK(ClosedDate)), 
  ROUND(
    (
      (
        5 * (
          FLOOR((ClosedDate - CreatedDate) / 7) + 
          MIN(1, MOD(ClosedDate - CreatedDate, 7) + 
          MIN(1, IF(MOD(CreatedDate - DATE(1900,1,8), 7) = 6, 1, 0))))
        ) + 
        MIN(5, 24/8 * (MOD(ClosedDate - CreatedDate, 1))) - 
        MIN(5, 24/8 * (MOD(CreatedDate - DATE(1900,1,8), 1)))
      ) * 24, 
      2
    ),
    null
  )
Also refer -> https://developer.salesforce.com/forums/?id=906F00000008xkfIAA


If it helps please mark this as Best Answer.
Thank you.