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
Matheus Antonio da SilvaMatheus Antonio da Silva 

Validation Rule - Age higher than 17 years old

Hello guys!

I've been struggling with a validation rule. There is a field called "Birthday" where the user populates his/her birthday. When the user populates this field, then it has to allow only ages higher than 17 years old.

For example:
User's birthday: 02/02/2005
Today's date: 15/05/2019
So it means that the user's age is bellow 18, hence it is not accepted. 

How can I do it? I've made it doing the following code, but it didn't work as I wanted:
(TODAY() - DadosPF_DataNascimento__c < 18*365)

I did other things, but there were incorret datas that were allowed instead of being denied. Could you guys please help me? 
 
Raj VakatiRaj Vakati
Use this
 
(( TODAY() - DadosPF_DataNascimento__c ) / 365.2425) >17

 
Raj VakatiRaj Vakati
http://naveendhanaraj.blogspot.com/2016/05/formula-and-validation-rule.html
https://developer.salesforce.com/forums/?id=906F00000008wdEIAQ
https://www.marksgroup.net/blog/salesforce-com-adding-a-formula-field-to-calculate-age-from-another-date-field/
Jega DeivaJega Deiva
Hi

  Please try this formula below:
         
                YEAR(TODAY())  - YEAR(Birthday__c)  <= 17


 Hope this will help you.

Thanks,
Jega
Matheus Antonio da SilvaMatheus Antonio da Silva
Hi Jega! I really appreciate your help, but also didn't work! I tried another solution, and finally it worked. Look at that:
TODAY() - DadosPF_DataNascimento__c < 6574
It worked through and through.
Thanks for supporting me guys!
Esteban Lezama RREsteban Lezama RR

I had to do it for 18: TODAY() >= ADDMONTHS(Birthdate__c,216)
for 17 it should be: TODAY() >= ADDMONTHS(Birthdate__c,204)

 

JJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJJ
Esteban's method is the most accurate one! Thanks mate
Rahul kumar 976Rahul kumar 976
Please Check this once 

today()- Date_of_Birth__c < 17*365
Edna BrownEdna Brown

To create a validation rule that allows only ages higher than 17 years old based on the "Birthday" field, you can use the following formula:
Today() - DATEVALUE(Birthday__c) < 18*365

Here's an explanation of the formula:
Today() represents the current date.
DATEVALUE(Birthday__c) converts the "Birthday" field into a date value.
Today() - DATEVALUE(Birthday__c) calculates the difference between the current date and the "Birthday" date in days.
18*365 represents 18 years converted into days. Note that this is an approximation and does not account for leap years.
The comparison Today() - DATEVALUE(Birthday__c) < 18*365 checks if the calculated difference is less than 18 years.
By using this formula in your validation rule, it will only allow ages higher than 17 years old, denying any entry where the age is equal to or less than 17 years.
Make sure to replace Birthday__c with the actual API name of the "Birthday" field in your Salesforce org. https://mcdvoice.me/
xim edaxim eda
Please let me know if you're looking for a article author for your weblog. You have some really good articles and I believe I would be a good asset. If you ever want to take some of the load off, I'd love to write some content for your blog in exchange for a link back to mine. Please shoot me an e-mail if interested. Many thanks!  Costco Ess login requirement