Handling date profile fields
Adding dates to your custom profile.
This has only been tested with 4.7.0
This module adds a birthday into the custom profile, but you can easily customize it to add any date, such as date of death for a obituary (for a famous actor's profile maybe). You must have made a template.php already. This code should be added to your user_profile.tlp.php file.
<div class="fields"><b>Birthday:</b> <?php print $user->profile_birthday['month']."/".$user->profile_birthday['day']."/".$user->profile_birthday['year'];?>Note that you will have to customize the profile_birthday to whatever your settings are in admin/settings/profile. To change the date layout, just move the month, day, and year around, like so:
<div class="fields"><b>Birthday:</b> <?php print $user->profile_birthday['year']."/".$user->profile_birthday['month']."/".$user->profile_birthday['day'];?>Convert date array to date variable
Here's a simple function that will convert the profile date array to a date variable. Maybe a little clunky but you get the point:
<?php
function convert_profile_date($profile_date_ar) {
// takes a profile date array and converts it to a date variable.
$output = mktime(0, 0, 0, $profile_date_ar['month'], $profile_date_ar['day'], $profile_date_ar['year']);
return $output;
}
?>Then you can pass the results to the php date function and format any way you want:
<?php
$converted_date = convert_profile_date($user->profile_birthday);
print date('F j, Y', $converted_date);
?>
I've tested it with Drupal
I've tested it with Drupal 5.3 and everything seemed to went well.
http://www.geektips.net