5

Age is displayed on a contact record but only DOB is a token available in message templates.

Are there any extensions that make age available for use? I've not been able to locate anything.

5

This sounded like a useful feature, so I added Age tokens to Eileen's CiviTokens extension, which seems to be the most widely used extension of its kind. Until a new release comes out, you'll have to pull from the master branch of the git repo.

  • Amazing. Thank you. Pulling shortly. – Justin Moore Dec 22 '19 at 15:38
5

I don't see any either, but the code to use in such an extension (as either a token or even a smarty modifier) seems pretty straightforward:

https://github.com/civicrm/civicrm-core/blob/5.19.2/CRM/Contact/BAO/Contact.php#L2677-L2684

      if ($contact->birth_date) {
        $birthDate = CRM_Utils_Date::customFormat($contact->birth_date, '%Y%m%d');
        if ($birthDate < date('Ymd')) {
          $age = CRM_Utils_Date::calculateAge($birthDate);
          $values['age']['y'] = CRM_Utils_Array::value('years', $age);
          $values['age']['m'] = CRM_Utils_Array::value('months', $age);
        }
      }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.