Calculate Contact age in a Drupal view












1















I'm exposing civi contact data in a drupal view. I can expose date of birth, but not the contact age field.



Anyone know of a module/ combination of modules that will allow me to calculate age in years within the view?










share|improve this question



























    1















    I'm exposing civi contact data in a drupal view. I can expose date of birth, but not the contact age field.



    Anyone know of a module/ combination of modules that will allow me to calculate age in years within the view?










    share|improve this question

























      1












      1








      1








      I'm exposing civi contact data in a drupal view. I can expose date of birth, but not the contact age field.



      Anyone know of a module/ combination of modules that will allow me to calculate age in years within the view?










      share|improve this question














      I'm exposing civi contact data in a drupal view. I can expose date of birth, but not the contact age field.



      Anyone know of a module/ combination of modules that will allow me to calculate age in years within the view?







      drupal-views






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 11 hours ago









      Craig AlmondCraig Almond

      537313




      537313






















          2 Answers
          2






          active

          oldest

          votes


















          4














          In your view, pull in the CiviCRM birth date field.
          Under date format, select Time ago
          This will present the B.O.B. field as 40 years 7 months



          enter image description here



          To remove years and months from the output you can ‘Rewrite results’ in the view and ‘Trim this field to a maximum length’ and set ‘Maximum length’ to 2 characters






          share|improve this answer
























          • Absolutely Awesome. Thank you Anil

            – Craig Almond
            9 hours ago



















          1














          You need to add views php module



          Add the dob into a view. In this example called birth_date



          Add a global php field.



          Then put this code into the output code box in the global php field



          <?php 
          $ageTime = $row->birth_date;
          $t = time();
          $age = $t-$ageTime;
          $year = 60 * 60 * 24 * 365;
          $ageYears = $age / $year;
          print floor($ageYears);
          ?>





          share|improve this answer
























          • Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP

            – Craig Almond
            9 hours ago











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "605"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          noCode: true, onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcivicrm.stackexchange.com%2fquestions%2f28721%2fcalculate-contact-age-in-a-drupal-view%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          4














          In your view, pull in the CiviCRM birth date field.
          Under date format, select Time ago
          This will present the B.O.B. field as 40 years 7 months



          enter image description here



          To remove years and months from the output you can ‘Rewrite results’ in the view and ‘Trim this field to a maximum length’ and set ‘Maximum length’ to 2 characters






          share|improve this answer
























          • Absolutely Awesome. Thank you Anil

            – Craig Almond
            9 hours ago
















          4














          In your view, pull in the CiviCRM birth date field.
          Under date format, select Time ago
          This will present the B.O.B. field as 40 years 7 months



          enter image description here



          To remove years and months from the output you can ‘Rewrite results’ in the view and ‘Trim this field to a maximum length’ and set ‘Maximum length’ to 2 characters






          share|improve this answer
























          • Absolutely Awesome. Thank you Anil

            – Craig Almond
            9 hours ago














          4












          4








          4







          In your view, pull in the CiviCRM birth date field.
          Under date format, select Time ago
          This will present the B.O.B. field as 40 years 7 months



          enter image description here



          To remove years and months from the output you can ‘Rewrite results’ in the view and ‘Trim this field to a maximum length’ and set ‘Maximum length’ to 2 characters






          share|improve this answer













          In your view, pull in the CiviCRM birth date field.
          Under date format, select Time ago
          This will present the B.O.B. field as 40 years 7 months



          enter image description here



          To remove years and months from the output you can ‘Rewrite results’ in the view and ‘Trim this field to a maximum length’ and set ‘Maximum length’ to 2 characters







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 9 hours ago









          Anil - MillerTechAnil - MillerTech

          98818




          98818













          • Absolutely Awesome. Thank you Anil

            – Craig Almond
            9 hours ago



















          • Absolutely Awesome. Thank you Anil

            – Craig Almond
            9 hours ago

















          Absolutely Awesome. Thank you Anil

          – Craig Almond
          9 hours ago





          Absolutely Awesome. Thank you Anil

          – Craig Almond
          9 hours ago











          1














          You need to add views php module



          Add the dob into a view. In this example called birth_date



          Add a global php field.



          Then put this code into the output code box in the global php field



          <?php 
          $ageTime = $row->birth_date;
          $t = time();
          $age = $t-$ageTime;
          $year = 60 * 60 * 24 * 365;
          $ageYears = $age / $year;
          print floor($ageYears);
          ?>





          share|improve this answer
























          • Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP

            – Craig Almond
            9 hours ago
















          1














          You need to add views php module



          Add the dob into a view. In this example called birth_date



          Add a global php field.



          Then put this code into the output code box in the global php field



          <?php 
          $ageTime = $row->birth_date;
          $t = time();
          $age = $t-$ageTime;
          $year = 60 * 60 * 24 * 365;
          $ageYears = $age / $year;
          print floor($ageYears);
          ?>





          share|improve this answer
























          • Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP

            – Craig Almond
            9 hours ago














          1












          1








          1







          You need to add views php module



          Add the dob into a view. In this example called birth_date



          Add a global php field.



          Then put this code into the output code box in the global php field



          <?php 
          $ageTime = $row->birth_date;
          $t = time();
          $age = $t-$ageTime;
          $year = 60 * 60 * 24 * 365;
          $ageYears = $age / $year;
          print floor($ageYears);
          ?>





          share|improve this answer













          You need to add views php module



          Add the dob into a view. In this example called birth_date



          Add a global php field.



          Then put this code into the output code box in the global php field



          <?php 
          $ageTime = $row->birth_date;
          $t = time();
          $age = $t-$ageTime;
          $year = 60 * 60 * 24 * 365;
          $ageYears = $age / $year;
          print floor($ageYears);
          ?>






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered 9 hours ago









          Tony HorrocksTony Horrocks

          71738




          71738













          • Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP

            – Craig Almond
            9 hours ago



















          • Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP

            – Craig Almond
            9 hours ago

















          Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP

          – Craig Almond
          9 hours ago





          Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP

          – Craig Almond
          9 hours ago


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to CiviCRM Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcivicrm.stackexchange.com%2fquestions%2f28721%2fcalculate-contact-age-in-a-drupal-view%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Paul Cézanne

          UIScrollView CustomStickyHeader Resize height generates problems when scroll is too fast

          Angular material date-picker (MatDatepicker) auto completes the date on focus out