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
Guilherme Eduardo de FariasGuilherme Eduardo de Farias 

How can I get the working days between two dates and put the result in a field ??

Hello, I've tried all the ways but I'm not getting it, I need that when I put the start date and end date they separate the working days and learn in the DiasTrabalhados__c field. I am not able to develop the necessary validation rule for such an action,
Thanks
Best Answer chosen by Guilherme Eduardo de Farias
Foram Rana RForam Rana R
Hi Eduardo,

​​​​​​​I hope you are doing well .....!!

Finding the Number of Business Days Between Two Dates

Calculating how many business days passed between two dates is slightly more complex than calculatingtotal elapsed days. The basic strategy is to choose a reference Monday from the past and find out howmany full weeks and any additional portion of a week have passed between the reference date and thedate you’re examining. These values are multiplied by five (for a five-day work week) and then the differencebetween them is taken to calculate business days.

Please use the below code:
(5 * ( FLOOR((date_1- DATE(1900,1, 8) ) / 7 ) ) + MIN(5, MOD(date_1- DATE(1900,1, 8), 7 ) ) )
-
(5 * ( FLOOR((date_2- DATE(1900,1, 8) ) / 7 ) ) + MIN(5, MOD(date_2- DATE(1900,1, 8), 7 ) ) )
In this formula, date_1 is the more recent date and date_2 is the earlier date. If your work week runsshorter or longer than five days, replace all fives in the formula with the length of your week.

Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.

Thanks & Regards,
Foram Rana



 

All Answers

ANUTEJANUTEJ (Salesforce Developers) 
Hi Guilherme,

I found the below article in which they mentioned how to get the day from thr date function "DAY( date )".

https://help.salesforce.com/articleView?id=formula_examples_dates.htm&type=5

Kindly let me know if this helps and please close the thread by marking a best answer so that it would be useful for others and also it would help in keeping the community clean.

Regards,
Anutej
Foram Rana RForam Rana R
Hi Eduardo,

​​​​​​​I hope you are doing well .....!!

Finding the Number of Business Days Between Two Dates

Calculating how many business days passed between two dates is slightly more complex than calculatingtotal elapsed days. The basic strategy is to choose a reference Monday from the past and find out howmany full weeks and any additional portion of a week have passed between the reference date and thedate you’re examining. These values are multiplied by five (for a five-day work week) and then the differencebetween them is taken to calculate business days.

Please use the below code:
(5 * ( FLOOR((date_1- DATE(1900,1, 8) ) / 7 ) ) + MIN(5, MOD(date_1- DATE(1900,1, 8), 7 ) ) )
-
(5 * ( FLOOR((date_2- DATE(1900,1, 8) ) / 7 ) ) + MIN(5, MOD(date_2- DATE(1900,1, 8), 7 ) ) )
In this formula, date_1 is the more recent date and date_2 is the earlier date. If your work week runsshorter or longer than five days, replace all fives in the formula with the length of your week.

Hope this helps you.
If this helps kindly mark it as solved so that it may help others in the future.

Thanks & Regards,
Foram Rana



 
This was selected as the best answer
sachinarorasfsachinarorasf
Hi Guilherme Eduardo de Farias,

Please go through the following links for the formula to get the working days between two dates.

https://stackoverflow.com/questions/252519/count-work-days-between-two-dates
https://developer.salesforce.com/forums/?id=906F00000008wNHIAY
https://developer.salesforce.com/forums/?id=906F0000000BPO7IAO
https://developer.salesforce.com/forums/?id=9060G0000005pjSQAQ

I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Sachin Arora
www.sachinsf.com