Advertisement
martyychang

Contact Age Formula Field (Salesforce)

Apr 1st, 2014
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* If no Birthdate is known,
  2.    leave the age blank */
  3.  
  4. IF( ISBLANK( Birthdate ) , NULL ,
  5.  
  6.   /* Max age determined by the difference in the
  7.      year number */
  8.  
  9.   YEAR( TODAY() ) - YEAR( Birthdate )
  10.  
  11.     /* Make an adjustment based on whether the
  12.        birth month and day has come and passed
  13.        in the current year */
  14.  
  15.     + IF( (
  16.  
  17.       /* Assuming there are 31 days in every
  18.          month allows us to make a quick
  19.          arithmetic comparison between two
  20.          month-day-of-month combinations */
  21.  
  22.       MONTH( TODAY() ) * 31 + DAY( TODAY() ) )
  23.         < ( MONTH( Birthdate ) * 31 + DAY( Birthdate )
  24.  
  25.     /* Make an adjustment to reach the real age
  26.        by subtracting one from the max age when
  27.        the person's birthday has not yet arrived
  28.        in the current year */
  29.  
  30.     ) , -1 , 0 )
  31. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement