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
Riz234Riz234 

Validation that exclude weekend (weekend Thursday and Friday)

We work in Saudi arabia and weekends are Thursday and Friday.

 

I have one custom Date field "Needed Date".

 

I want to create a validation. that should restrict user to submit the record if "Needed Date" is less than 3 business days from Today.

 

Eg: Today is 18th Apr and wednesday

if Needed date is 22 Mar (validation should occur; it is more than 3 days but there is weekend in between)

if Needed Date is 23rd Apr(no validation)

 

What should be the formula ? Weekends are thursday and friday.


 Need help and Support.

Best Answer chosen by Admin (Salesforce Developers) 
Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below Validation Rule:

 

if(NeededDate__c <

CASE(

MOD(TODAY()- DATE(1900, 1, 7), 7),

0, TODAY()+3,

1, TODAY()+5,

2, TODAY()+5,

3, TODAY()+5,

4, TODAY()+4,

5, TODAY()+5,

6, TODAY()+3,

null),true,false)

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

All Answers

Navatar_DbSupNavatar_DbSup

Hi,

 

Try the below Validation Rule:

 

if(NeededDate__c <

CASE(

MOD(TODAY()- DATE(1900, 1, 7), 7),

0, TODAY()+3,

1, TODAY()+5,

2, TODAY()+5,

3, TODAY()+5,

4, TODAY()+4,

5, TODAY()+5,

6, TODAY()+3,

null),true,false)

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved. 

This was selected as the best answer
Riz234Riz234

Dear Navatar,

 

Thanks for your reply and solution.

 

It is working fine for three days, but I dont know whether it will work when needed date comes before weekend (Thu/Fri). Since, today is saturday so i have to wait till tuesday or wednesday to test it. Is there any other way to test ?

 

Can you explain me your formula so that i should be well aware how it is working. I see sometimes you are using Today()+3, sometimes Today()+4 and sometimes Today()+5, It would be better if you just descibe your formula.

 

Once again thanks for your support.

Riz234Riz234

Dear Ankit,

 

I tried your validation today as weekend is ahead and it is working fine. Thanks for your support.

 

Can you tell me how to add one condition to this validation, condition is that this validation should work only when status=initial.

 

Thanks and really appreciate your support.

Riz234Riz234

Dear Ankit,

 

I am using below validation and it looks ok to me, Can you please advise me.

 

if ( ISPICKVAL(Status__c, "Initial")  &&  Needed_Date__c < CASE( MOD(TODAY()- DATE(1900, 1, 7), 7), 0, TODAY()+3, 1, TODAY()+5, 2, TODAY()+5, 3, TODAY()+5, 4, TODAY()+4, 5, TODAY()+5, 6, TODAY()+3, null),true,false)

 

Thanks for your support