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
Anu Sharma 54Anu Sharma 54 

Hi, i have two field start date and end date I want to validation that is end date must be in between 2 to 6 month only How can i do that.

Hi,
i have two field start date and end date I want to validation that is end date must be in between 2 to 6 month only How can i do that.
Best Answer chosen by Anu Sharma 54
cczccz
Hi Anu,

First, create a formula field ( Months Between ) which returns number

IF(NOT(ISBLANK(End_Date__c)) && NOT(ISBLANK(Start_date__c))
     ,(((YEAR(End_Date__c ) - YEAR(Start_Date__c ) - 1) *12) + (12 - MONTH(Start_Date__c ) +1) + MONTH(End_Date__c ) - 1+ IF(DAY(End_Date__c ) > DAY(Start_Date__c ),1,0)))
     , null
)

After that create the following validation rule

((Months_Between__c ) < 2) || ((Months_Between__c) > 6)

If the answer helps you, please mark it as best answer. 

Thanks
Good luck
 

All Answers

cczccz
Hi Anu,

First, create a formula field ( Months Between ) which returns number

IF(NOT(ISBLANK(End_Date__c)) && NOT(ISBLANK(Start_date__c))
     ,(((YEAR(End_Date__c ) - YEAR(Start_Date__c ) - 1) *12) + (12 - MONTH(Start_Date__c ) +1) + MONTH(End_Date__c ) - 1+ IF(DAY(End_Date__c ) > DAY(Start_Date__c ),1,0)))
     , null
)

After that create the following validation rule

((Months_Between__c ) < 2) || ((Months_Between__c) > 6)

If the answer helps you, please mark it as best answer. 

Thanks
Good luck
 
This was selected as the best answer
Anu Sharma 54Anu Sharma 54
Thank you Catalin Cozea
cczccz
No problem.
If the answer is what you need please mark my answer as best answer.
Help the community so we can help you.
Thank you