I have been trying to get the user's date of birth and/or age to show in a custom profile and all the nsippets given on the custom profile support area have only shown the year 2007 instead of the age ofthe user or their actual birth date. I was wondering if anyone could provide me with some code to add to my custom user profile.

Comments

jacauc’s picture

subscribing

spyderpie’s picture

I am looking for a snippet too. - subscribing

demon326’s picture

hi,i have the full snippets but there not working

this is the code :

<div class="fields">
<?php
    $year_diff = date("Y") - ($user->profile_birthday{year});
    $month_diff = date("m") - ($user->profile_birthday{month});
    $day_diff = date("d") - ($user->profile_birthday{day});
    if ($month_diff < 0)
      $year_diff--;
    elseif ($month_diff == 0 && $day_diff < 0)
      $year_diff--;
?>
<p>Age: <?php print $year_diff; ?> </p>
</div> </p>

but thats not working it only shows the date of the current day and thats now for what where searching for

i hope somone can help us!

Haggle’s picture

I think the best way of finding it would be to look for what is printed in the default profile. I'm not as php savy as I'd like to be so I won't be able to find it. The code necessary is probably in the module itself and even marked with a comment of some sort.

spyderpie’s picture

:)

Got it ...

<?php $date_key = $user->DOB;
$year = $date_key{year};
$month = $date_key{month};
$day = $date_key{day};
?>
<div id="user_bday">
<?php
print 'Birthday: '.$month.'/'.$day.'/'.$year;
if ((date("m") == $date_key{month}) && (date("d") == $date_key{day})) { ?>
<p>Happy Birthday <?php print $user->name ?>!</p>
<?php } ?>
</div>

Julie

Haggle’s picture

Thank

maartenvg’s picture

A new version has been committed, in less than 24 hours you should be able to download it. Please test it for us, instructions are in the README file.

The changes also include a better way to format the birthdays and calculate the age.

To display the birthdate:

//assumes that $user is a User object

$field = variable_get('birthdays_field_name','');
echo birthdays_show_date($user->$field);
// or, for larger format
echo _birthdays_show_date($user->$field, 'medium');

To get the age:

$field = variable_get('birthdays_field_name','');
$age = _birthdays_calculate_age($user->$field);
maartenvg’s picture

Status: Active » Closed (fixed)
maartenvg’s picture

Getting the age is even more simple than I remember because the age is saved into the user object on loading:

// assuming $user is a User object
$age = $user->age
lvto2000’s picture

Component: Code » Code (Birthdays)

FROM YOUR README>>>>>>>>>

CUSTOMIZING THE MODULE
----------------------

Sometimes you might want to customize the way some areas of the module look.
For instance, you might want to alter the Birthdays page, or change the listing
in the Birthdays blocks. This can be done by overriding the theme functions.
How to do so can be found here: http://drupal.org/node/173880.

If you want to display the date of birth or age on another location (e.g. near
the username, in the forums, on nodes), you best use the functions
$age = _birthdays_show_age($account);
$date = _birthdays_show_date($date_array, $account, 'medium');

These will adhere to the global or user determined visibility of the age and
year of date.

More specific information might follow later.

>>>>> END OF YOUR README

MY CODE IN A PANELS PHP BLOCK >>>>>>

global $user;

if (module_exists('birthdays') && function_exists('_birthdays_show_age')) {   

// $age = _birthdays_show_age(1);  // tried this way then tried the next way
// $age = _birthdays_show_age($accounts) // tried both ways
$age = _birthdays_show_age($user->uid) // tried this way finally

$date = _birthdays_show_date($date_array, $account, 'medium');
echo "MODULE EXISTS  ";

} 

echo "hello";
echo $age;
echo $date;

NOTHING,,, NADDA... Nothing outputs other than the confirmation to me that the echo for "MODULE EXISTS" does fire. Also the "hello" echo fires. Otherwise, the functions dont seem to do anything at all. $age does not echo and neither does $date. I see that the developer changed how this works several times in this thread. Does anyone know if he changed it again? I am using the latest version for Drupal 6.28.

Any help would be appreciated.