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

Validation rule for 365 days range period

I have a requirement to create a validation rule to prevent creation of record when period between Effective date and Expiration Date is equal to 365 days.
The validation rule [(Expiration_Date__c) - (Effective_Date__c) == 365] works fine
The issue is we have an option to renew the record with a custom “Renew” button. When we renew the record, the effective and expiration dates copy form the old record and adds one year to it. Here the validation rule is throwing error when it is a leap year.

Example:  Effective date is 2/2/2015 and Expiration is 2/1/2016 for a record. When I try to renew the record, it throws validation rule since the number of days are calculated between the effective date (2/2/2016) and Expiration date (2/1/2017) as 365 days since it’s a leap year.( If it not a leap year there is no error, record gets saved)
Can anyone have any idea to handle this condition for leap year and calculate it in the validation rule?

Jason Reiber [ACS]Jason Reiber [ACS]

You could try calculating the components of the dates separately instead of a straight 365 difference.  So you could split the logic into 2 parts : 

(Expr Day/Month = Eff Day/Month + 1 day) AND (Expr Year = Eff Year + 1)

That way you don't have to build a bunch of extra logic to account for the extra day depending on the year.