Is there a way to pull a field from the profile ?

Comments

tommytom’s picture

is it possible or do I have to use Content Profile module that build user profiles as normal nodes.

tommytom’s picture

for example I'm trying to calculate and display the age of an user with this code:

$year_diff = date("Y") - ($account->profile_birthdate['year']);
$month_diff = date("m") - ($account->profile_dob['month']);
$day_diff = date("d") - ($account->profile_dob['day']);
if ($month_diff < 0)
  $year_diff--;
elseif ($month_diff == 0 && $day_diff < 0)
  $year_diff--;


$node_field[0]['value'] = $year_diff ;

but I always get the value "2009", so I think this is wrong: ($account->profile_birthdate['year'])

the date in the database is stored in this format: a:3:{s:5:"month";s:2:"12";s:3:"day";s:2:"28";s:4:"year";s:4:"1985";}

I found the code from this article: http://drupal.org/node/45763

Can somebody help me ?

tommytom’s picture

I solved the issue with this code:

global $user;
profile_load_profile($user);

$year_diff = date("Y") -  ( $user->profile_dob['year']);
$month_diff = date("m") - ($user->profile_dob['month']);
$day_diff = date("d") - ($user->profile_dob['day']);
if ($month_diff < 0)
  $year_diff--;
elseif ($month_diff == 0 && $day_diff < 0)
  $year_diff--;


$node_field[0]['value'] = $year_diff ;
mmjvb’s picture

Issue summary: View changes
Status: Active » Closed (outdated)