Calculate Contact age in a Drupal view
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
add a comment |
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
add a comment |
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
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
drupal-views
asked 11 hours ago
Craig AlmondCraig Almond
537313
537313
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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

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
Absolutely Awesome. Thank you Anil
– Craig Almond
9 hours ago
add a comment |
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);
?>
Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP
– Craig Almond
9 hours ago
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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

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
Absolutely Awesome. Thank you Anil
– Craig Almond
9 hours ago
add a comment |
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

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
Absolutely Awesome. Thank you Anil
– Craig Almond
9 hours ago
add a comment |
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

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
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

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
answered 9 hours ago
Anil - MillerTechAnil - MillerTech
98818
98818
Absolutely Awesome. Thank you Anil
– Craig Almond
9 hours ago
add a comment |
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
add a comment |
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);
?>
Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP
– Craig Almond
9 hours ago
add a comment |
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);
?>
Thanks Tony. Anil's suggestion has worked a charm. So I haven't needed to dabble with PHP
– Craig Almond
9 hours ago
add a comment |
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);
?>
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);
?>
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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