I'd like to add a custom field to the Contact Summary page that calculates and displays the time that the person being viewed has held a full membership.

In this case we have student, candidate and full memberships and a full member will have records for each in their membership tab, showing the transition dates from where their student membership ended and candidate membership started, where the candidate membership ended and their full membership started.

For the "Years as Full Member" custom field, we want to be able to glance at the summary page and see that a member has held a full membership for 9 years, 12 years, 25 years, etc... The calculation is simple enough but I don't know how to integrate it within CiviCRM/Drupal.

1 Answer 1


This requires you write an extension. I've written similar extensions to show the "original join date" on a contact summary screen. If you haven't written PHP, you will probably want to hire someone to do this for you.

Your case is a little trickier, because it'll need to be updated once a..day? Month? Whereas "original join date" only needs to be filled in once.

Here's the basic approach:

  • Create a custom field to store the data. Set it to view-only.
  • In your extension, define a new API. When the API is called, it should make an API call to find the folks whose custom field will need updating. If these folks are defined as a group/smart group, that will help!
  • Loop through each contact, using the API to query their memberships.
  • Take the earliest membership join date that applies and do your math, using PHP's date arithmetic functions.
  • Use the API to update the field that stores the data.
  • Define a scheduled job (Administer menu » System Settings » Scheduled Jobs) to run the scheduled job on the schedule of your choice.
  • Thanks Jon. I figured I might need to build an extension but hoped there was a native method. Oh well... I guess I'll have to poke around in Civi's api explorer to see if I can grab the info, stuff it in a custom field and refresh it once a day. It seems a bit clunky but I guess it'll have to do. Cheers. Aug 30, 2016 at 6:19
  • Note: If anyone has a native solution, I'm all ears. Aug 30, 2016 at 19:22
  • PCPs don't yet have an API! It's on my plate to finish adding them: github.com/civicrm/civicrm-core/pull/7878 Aug 31, 2016 at 17:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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