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
Robert EssenRobert Essen 

A validation rule on a Date/Time field

Hi, i am struggling getting the right formule.

I've been asked to create a validation rule on a Date/Time field. Expiration_date__c, can be set to a maximum of 4 weeks from Creation date

This is what i have so far (since the original request was 2 Months), but it doesn't give me the right expiration date

IF(AND(Value(TEXT((YEAR(DATEVALUE(DateExpired__c))*12+MONTH(DATEVALUE(DateExpired__c)))-
(YEAR( TODAY() )*12+MONTH( TODAY())))) > 2,OR(ISPICKVAL(Status,'Draft'),ISPICKVAL(Status,'Review'))),true,false)

any advise is welcome, thanks
Kind regards

Sai PraveenSai Praveen (Salesforce Developers) 
Hi Robert,

As noew the formule is for 4 weeks means 28 days You can use direcltly the below formula.
 
DateExpired__c-Now() > 28

If this solution helps, Please mark it as best answer.

Thanks,
 
Daniel AhlDaniel Ahl
Hello Robert,
Expiration_date__c > CreatedDate + 28 // Checks if the Expiration is more than 28 days away from created date.

This would assume that there is a value in the CreatedDate (which it won't have when creating the record), so you'd probably want to add a check for Expiration_date__c > TODAY() + 28 for when CreatedDate doesnt have a value.

 


 
Robert EssenRobert Essen

Thanks for thinking along guys,

Not sure if this covers the need though.

The requirements actually is, to give some staff (by permission set) the posibillity to update a Date/time field (on quote) named DateExpired__c, which is already filled with a (future) date (i.e. 26-3-2022 1:00) to be able to extend it with a maximum of 1 month ( so 26-4-2022 1:00)
thanks for you help