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
Kiran kumar 193Kiran kumar 193 

Return date by substracting 2 days from Priority date and Need to exclude weekends

Hi,
My requirement is is Return date by substracting 2 days from the Priority date and Need to exclude weekends.
If Priority date is
MONDAY (ex: 4/26/2021)- Return last THRUSDAY Date(4/22/2021)
TUESDAY(ex: 4/27/2021)- Return last FRIDAY Date(4/23/2021)
WEDNESDAY(ex: 4/28/2021)- Return MONDAY Date(4/26/2021)
THRUSDAY(ex: 4/29/2021)- Return TUESDAY Date(4/27/2021)
FRIDAY(ex: 4/30/2021)- Return WEDNESDAY Date(4/28/2021)
Below logic is working fine for wednesday,thrusday,friday dates but for monday,tuesday it was returning weekend dates. Appriciate help
CASE(
MOD( DATEVALUE(Priority_Date__c)- DATE(1900, 1, 2), 2),
0, Priority_Date__c-4, 
1, Priority_Date__c-2, 
2, Priority_Date__c-2, 
3, Priority_Date__c+1, 
4, Priority_Date__c+1, 
5,Priority_Date__c+3, 
6,Priority_Date__c+2, 

Priority_Date__c)
ANUTEJANUTEJ (Salesforce Developers) 
Hi Kiran,

>> https://salesforcemann.wordpress.com/2016/12/04/the-ultimate-salesforce-formula-to-add-business-days-to-a-date/

In the above link, there is an explanation of how to add business days I think you can use the same and alter it to subtract that will fit your use case.

Let me know if it helps you and close your query by marking it as solved so that it can help others in the future.  

Thanks.
Kiran kumar 193Kiran kumar 193
That is for returning busiess days. Mine was to return date . if you know the exact formula you can help me

Thanks