Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
ShowAll Questionssorted byDate Posted
Shoshinsha81

I would like to create a formula based on the Case Opened date and Case close date.
Schedule - Monday to Thursday 8 am to 8 pm
Schedule - Friday = 8 am to 6 pm

Mahesh D
Hi Shishinsha,

I have a similar formula where I am finding the Age of the Case.

```IF(DATEVALUE(CreatedDate) <> TODAY(),
IF(
AND(
(5 - (CASE(MOD( DATEVALUE(CreatedDate) - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) < (CASE(MOD( TODAY() - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)) ),
((( TODAY() - DATEVALUE(CreatedDate)) + 1) < 7)
),
/** Value to YES */
(
(CASE(MOD( TODAY() - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0)) - (5 - (CASE(MOD( DATEVALUE(CreatedDate) - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0))) -1
),
/** Value to NOT */
(
((FLOOR((( TODAY() - DATEVALUE(CreatedDate) ) - (CASE(MOD( DATEVALUE(CreatedDate) - DATE(1900, 1, 6), 7), 0, 0, 1, 6, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0))) / 7)) * 5) +
(CASE(MOD( DATEVALUE(CreatedDate) - DATE(1900, 1, 6), 7), 0, 0, 1, 5, 2, 5, 3, 4, 4, 3, 5, 2, 6, 1, 0)) +
(CASE(MOD( TODAY() - DATE(1900, 1, 6), 7), 0, 0, 1, 0, 2, 1, 3, 2, 4, 3, 5, 4, 6, 5, 0))
) - 1
)
,0)```

You may have to change Today() to Case Close Date and it will work.

Please do let me know if it helps you.

Regards,
Mahesh
Debasis
If you want to write for for this then I have a sample code which is usually calculating business days and you can multiply time with that day calculation. Check below blog for sample code.
`http://sfdcbydev.blogspot.ae/2016/01/working-day-calculation-apex.html?m=1 `
Debasis
`https://help.salesforce.com/HTViewSolution?id=000004526`
AG_SFDC
Hello,

Create a Formula Field with return type of Text and try this
```IF(
CASE(MOD((DATEVALUE(CreatedDate))- DATE(1900,1,7), 7), 0, 'Sunday', 1,
'Monday',2,'Tuesday',3,'Wednesday',4,'Thursday',5,
'Friday',6,'Saturday','error') = 'Monday',
'Monday 8 am to 8 pm',
IF(
CASE(MOD((DATEVALUE(CreatedDate))- DATE(1900,1,7), 7), 0, 'Sunday', 1,
'Monday',2,'Tuesday',3,'Wednesday',4,'Thursday',5,
'Friday',6,'Saturday','error') = 'Tuesday',
'Tuesday 8 am to 8 pm',
IF(
CASE(MOD((DATEVALUE(CreatedDate))- DATE(1900,1,7), 7), 0, 'Sunday', 1,
'Monday',2,'Tuesday',3,'Wednesday',4,'Thursday',5,
'Friday',6,'Saturday','error') = 'Wednesday',
'Wednesday 8 am to 8 pm',
IF(
CASE(MOD((DATEVALUE(CreatedDate))- DATE(1900,1,7), 7), 0, 'Sunday', 1,
'Monday',2,'Tuesday',3,'Wednesday',4,'Thursday',5,
'Friday',6,'Saturday','error') = 'Thursday',
'Thursday8 am to 8 pm',

IF(
CASE(MOD((DATEVALUE(CreatedDate))- DATE(1900,1,7), 7), 0, 'Sunday', 1,
'Monday',2,'Tuesday',3,'Wednesday',4,'Thursday',5,
'Friday',6,'Saturday','error') = 'Friday',
'Friday = 8 am to 6 pm',
'It Is Weekend'
)
)
)
)
)```

Let me know if it worked for you!

Thanks,
AG