Handling date profile fields
Adding dates to your custom profile.
This has only been tested with 4.7.0 and 5.3
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);
?>
D6 error with convert_profile_date()
Received this error when I tried to put that last snippet into Drupal 6.8:
Did you enable a module with the invoked function?
It doesn't come with Drupal, you have to add it in.
I have successfully used the snippet in D6 (latest release 6.12).
Victor Kane
http://awebfactory.com.ar
Victor Kane
http://awebfactory.com.ar
Same here. It's a very handy
Same here. It's a very handy function. I started using it because you can't just use the "format_date" code.
Please consider joining my site: http://www.getlives.com
Thank you. -GetLives
Great Script
Love the script, I did a small change though so I can use one function in template files.
<?phpfunction convert_profile_date($profile_date_ar, $formate) {
// 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']);
$output = date($formate, $output);
return $output;
}
?>
This lets you pass your date format to the convert_profile_date function. Now you can use for example:
<?phpconvert_profile_date($account->profile_date_of_birth, 'F j, Y');
?>
http://www.ianhoar.com
Ian Hoar - Passion for Technology - Geeking Out