You need to sign in to do that
Don't have an account?
monkeyking
Logic for calculating difference between two dates excluding weekends
Hello All,
I have a query regarding the login in calculating the difference between two dates excluding weekends.
I have a formula field in our org, which calculates the difference between two dates(Closed date - opened date). But this formula field also includes weekends.
I require a formula which should calculate the difference between two dates exlcuding weekends.
Please help me.
Thank you.
I have a query regarding the login in calculating the difference between two dates excluding weekends.
I have a formula field in our org, which calculates the difference between two dates(Closed date - opened date). But this formula field also includes weekends.
I require a formula which should calculate the difference between two dates exlcuding weekends.
Please help me.
Thank you.
i think this is actually inthe salesforce document
https://resources.docs.salesforce.com/218/latest/en-us/sfdc/pdf/salesforce_useful_formula_fields.pdf
CASE(MOD( openedDate- DATE(1985,6,24),7),
0 , CASE( MOD( ClosedDate__c - openedDate__c,7),1,2,2,3,3,4,4,5,5,5,6,5,1),
1 , CASE( MOD( ClosedDate__c - openedDate__c,7),1,2,2,3,3,4,4,4,5,4,6,5,1),
2 , CASE( MOD( ClosedDate__c - openedDate__c,7),1,2,2,3,3,3,4,3,5,4,6,5,1),
3 , CASE( MOD( ClosedDate__c - openedDate__c,7),1,2,2,2,3,2,4,3,5,4,6,5,1),
4 , CASE( MOD( ClosedDate__c - openedDate__c,7),1,1,2,1,3,2,4,3,5,4,6,5,1),
5 , CASE( MOD( ClosedDate__c - openedDate__c,7),1,0,2,1,3,2,4,3,5,4,6,5,0),
6 , CASE( MOD( ClosedDate__c - openedDate__c,7),1,1,2,2,3,3,4,4,5,5,6,5,0), 999) + (FLOOR(( ClosedDate__c - openedDate__c)/7)*5)
Hope this helps, Please mark this as the best solution this helps
Thanks
Shubham Kumar
Hello Shubham,
Thanks or your reply.
When i try this i am getting the below error,
This is because CloseDate is a date field while CreatedDate is a Date/Time Field
Try this formula
CASE(MOD( CloseDate - DATE(1985,6,24) ,7),
0 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate) ,7),1,2,2,3,3,4,4,5,5,5,6,5,1),
1 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,2,2,3,3,4,4,4,5,4,6,5,1),
2 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,2,2,3,3,3,4,3,5,4,6,5,1),
3 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,2,2,2,3,2,4,3,5,4,6,5,1),
4 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,1,2,1,3,2,4,3,5,4,6,5,1),
5 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,0,2,1,3,2,4,3,5,4,6,5,0),
6 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,1,2,2,3,3,4,4,5,5,6,5,0), 999) + (FLOOR(( CloseDate - DATEVALUE(CreatedDate))/7)*5)
Hope this helps, Please mark this as the best solution this helps
Thanks
Shubham Kumar
Still i am getting the same error.
I assume CreatedDate and CloseDate both are opportunity`s standard fields here.
Can you please try this again and let me know.
CASE(MOD( DATEVALUE(CreatedDate) - DATE(1985,6,24) ,7),
0 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate) ,7),1,2,2,3,3,4,4,5,5,5,6,5,1),
1 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,2,2,3,3,4,4,4,5,4,6,5,1),
2 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,2,2,3,3,3,4,3,5,4,6,5,1),
3 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,2,2,2,3,2,4,3,5,4,6,5,1),
4 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,1,2,1,3,2,4,3,5,4,6,5,1),
5 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,0,2,1,3,2,4,3,5,4,6,5,0),
6 , CASE( MOD( CloseDate - DATEVALUE(CreatedDate),7),1,1,2,2,3,3,4,4,5,5,6,5,0), 999) + (FLOOR(( CloseDate - DATEVALUE(CreatedDate))/7)*5)
Sorry for the late reply.
Both the fields are Case object fields not opportunity fields.
Thank you.
Regards,
Rajkumar CV