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
AnonymouseAnonymouse 

How to Validate Custom Date Field to Current or Future Year

Hello,

How may I validate 2 custom date fields to make sure that both are of the current or future year?

This is what I have so far:
 
AND(OR (YEAR(customField1__c) < YEAR(Today()),
YEAR( customField2__c) < YEAR(Today())), true, false)

Any help would be greatly appreciated.

Sincerely,
Jackie​
Best Answer chosen by Anonymouse
Maharajan CMaharajan C
Hi Jaquelyne ,

Based the below one both the custom fields should be lesser than this or future year then only it will fire. Because you have use the AND logic.

IF( AND( (YEAR(customField1__c) < YEAR(Today())), (YEAR(customField2__c) < YEAR(Today())) ),true, false )

So if you want like if anyone of this custom field is past then you want fire use the OR logic.

IF( OR( (YEAR(customField1__c) < YEAR(Today())), (YEAR(customField2__c) < YEAR(Today())) ),true, false )

And also check the Validation rule is Active

 Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!

Thanks,
Raj





 

All Answers

Raj VakatiRaj Vakati
AND(
YEAR(customField1__c) > YEAR(Today()),
YEAR( customField2__c) > YEAR(Today()))
)

 
Raj VakatiRaj Vakati
IF(
AND((
YEAR(customField1__c) < YEAR(Today()),
YEAR( customField2__c) < YEAR(Today()))
),true , false 
)
AnonymouseAnonymouse

Hi Raj,

I'm afraid it's not working.

This is what I currently have:

IF( 
AND( 
(YEAR(customField1__c) < YEAR(Today())), 
(YEAR(customField2__c) < YEAR(Today())) 
),true, false 
)

I get no errors if I try to create a record with a year that is not current or future. It lets me create the incorrect record with an invalid year. :(

Sincerely,
Jackie

Raj VakatiRaj Vakati
IF( 
AND( 
(YEAR(customField1__c) < YEAR(Today())), 
(YEAR(customField2__c) < YEAR(Today())) 
),false, true
)

 
Raj VakatiRaj Vakati
Still not working ?
Maharajan CMaharajan C
Hi Jaquelyne ,

Based the below one both the custom fields should be lesser than this or future year then only it will fire. Because you have use the AND logic.

IF( AND( (YEAR(customField1__c) < YEAR(Today())), (YEAR(customField2__c) < YEAR(Today())) ),true, false )

So if you want like if anyone of this custom field is past then you want fire use the OR logic.

IF( OR( (YEAR(customField1__c) < YEAR(Today())), (YEAR(customField2__c) < YEAR(Today())) ),true, false )

And also check the Validation rule is Active

 Can you please Let me know if it helps or not!!!

If it helps don't forget to mark this as a best answer!!!

Thanks,
Raj





 
This was selected as the best answer
Narender Singh(Nads)Narender Singh(Nads)
Hi Jaquelyne,

You should be using OR instead of AND.

Use this:

OR(
YEAR(customField1__c) > YEAR(Today()),
YEAR( customField2__c) > YEAR(Today()))
)

Let me know if it helps.
Thanks
AnonymouseAnonymouse
Thank you Raj, Maharajan, and Narender.