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
DevLauraDevLaura 

How do I write a workflow to check an Under Age 18 box?

I'm trying to create a formula field that will look at a person's birthdate and check an "Under 18" checkbox. Then, I need to create another formula or workflow that will uncheck it once they turn 18 and check an "18 and over" checkbox OR will just check the "18 and over" checkbox for those people that are over 18. I'm not the greatest with anything math-related and could use some help. Thank you in advance!
Raj VakatiRaj Vakati
Use this formula with return type as text 
Data Type	Formula	 	 
IF( NOT( ISBLANK( Birthdate ) ) , 

IF( IF( DATE( 2000 , MONTH( Birthdate ) , DAY( Birthdate ) ) <= DATE( 2000 , MONTH( TODAY() ) , DAY( TODAY() ) ), 
YEAR (Today()) - YEAR ( Birthdate ), 
YEAR (Today()) - YEAR ( Birthdate ) -1 ) >18 ,"Above 18 " , "Under 18") , 


'Under 18')



 
DevLauraDevLaura
What if it has to check a checkbox though?
Waqar Hussain SFWaqar Hussain SF
Hi Laura, 

You can create a formula field with return type decimal. And use the below formula which will calculate the age. 
 
IF( NOT( ISBLANK( Birthdate ) ) , 
Birthdate /365.2425, 
null)

Then based on age (above formula field) You can create another checkbox formula field to calculate under 18 and 18+ checkboxex. 

Do let me know If you have any further query.

Thanks
Maxwell LessardMaxwell Lessard
I'd create a Formula Field with the Checkbox format called "Under Age 18?" that has the following code:
OR(YEAR(TODAY())-YEAR(Birthday__c)  <  18, 
YEAR(TODAY())-YEAR(Birthday__c)  =  18 && MONTH(TODAY())> MONTH(Birthday__c,
YEAR(TODAY())-YEAR(Birthday__c)  =  18 && MONTH(TODAY()) <= MONTH(Birthday__c && DAY(TODAY()) > DAY(Birthday__c)   
     )


You can do the same thing for an "18 and over" checkbox with this code instead:
 
NOT(Under_Age_18__c)

 
DevLauraDevLaura
Thank you!
Maxwell LessardMaxwell Lessard
just noticed a small mistake in my code. you should use the following code instead! 
OR(YEAR(TODAY())-YEAR(Birthday__c)  <  18, 
YEAR(TODAY())-YEAR(Birthday__c)  =  18 && MONTH(TODAY()) > MONTH(Birthday__c,
YEAR(TODAY())-YEAR(Birthday__c)  =  18 && MONTH(TODAY()) = MONTH(Birthday__c && DAY(TODAY()) >= DAY(Birthday__c)   
     )

 
Sorna JenefaSorna Jenefa
Please try the below one:

Over 18 

Return Type: Check box

IF(YEAR(TODAY())-YEAR(Birthdate__c ) >18, true,false)

Under 18

Return Type: Check box     
     
IF(YEAR(TODAY())-YEAR(Birthdate__c ) <18, true,false)

Use this formula to check the checkbox.

Let me know if its works as you excepted.

Thanks,
Jenefa
Sweet Potato Tec