Community Documentation

Handling date profile fields

Last updated August 27, 2009. Created by freehunter on July 26, 2006.
Edited by ronald_istos, bekasu, add1sun, sepeck. Log in to edit this page.

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);
?>

Comments

D6 error with convert_profile_date()

Received this error when I tried to put that last snippet into Drupal 6.8:

Call to undefined function convert_profile_date()

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

Great Script

Love the script, I did a small change though so I can use one function in template files.

<?php
function 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:

<?php
    convert_profile_date
($account->profile_date_of_birth, 'F j, Y');
?>

http://www.ianhoar.com
Ian Hoar - Passion for Technology - Geeking Out

http://www.ianhoar.com
Ian Hoar - Passion for Technology - Geeking Out

for profile and

for profile and birthdays.module, a user can hide their birth date from their profile or just hide the year.

if i use this snippets, how can i make used of that functions? it will display the whole date whether or not the user set it to hide.

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x
Audience
Themers

Theming Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.