I've created a customer php page to display users in a set format given that they are in the teachers group.
http://ride4.org/beacon/?q=node/5

I've added the custom fields. In particular I've added a "Date Employed" field which in the DB the value is a:3:{s:5:"month";s:1:"5";s:3:"day";s:2:"25";s:4:"year";s:4:"2006";}

I need to take this date and convert it to a standard m/d/yy date.
I tried http://drupal.org/node/75598 but that just gave an error saying that the function expects a long value

Is there an easy way to take this value in the DB and convert it to the standard date format?

Comments

agentrickard’s picture

That data object is a serialized array. Use unserialize(), then you can use mktime() and pass the results to format_date().

--
http://ken.therickards.com

Cubic8’s picture

I did this...

// Get $user like this so we load the profile values too
$uid = $GLOBALS['user']->uid;
$user = user_load(array('uid' => $uid));

// I have a 'date' field - this is returned as an array, so no need for unserialize()
$val = $user->profile_duedate;

// Now convert to my required format
$datedue = mktime(0, 0, 0, $val['month'], $val['day'], $val['year']);
$date = format_date($datedue, 'custom', 'l dS F Y');

print $date;

Thanks to http://drupal.org/node/202092 for retreiving the profile field.

Cubic8’s picture

Ah I discoved there's a simpler way to get the profile fields loaded - call profile_load_profile()
e.g.


global $user;
profile_load_profile($user);

// etc...

tpainton’s picture

Are you using the date module? IF you are using the standard User Profile, what you might consider to save some time down the road (possibly) is to use the Content Profile Module. This will turn your user profiles into content nodes. From there, you can apply a Date CCK field.