Date display in Profiles and elsewhere
blarg - April 15, 2006 - 04:53
I have users that have each created a profile. In this profile they note their date of birth. These are all showing everywhere as:
1970-05-10 H:i
Obviously we don't care about the hours and seconds. In the configuration I see a short date format that includes hours and seconds, but none are availiable that don't have this. Which db table is this format stored in so I can axe the H:i or is there an easier way to accomplish this?

More research
I found the date formats in the variable table, but the short format is:
YYYY-MM-DD - H:i
Note the dash in the middle. So I looked at the profile fields and the date is stored like:
a:3:{s:4:"year";s:4:"1983";s:5:"month";s:1:"4";s:3:"day";s:2:"27";}
I don't know what the letter:number is for, but this is obviously getting fed through a date-prettier-upper that isn't the main one, because I set the date formats to year-month-day with nothing else and we still showed H:i. I did turn the cache off to make sure that wasn't the issue.
Profile module bug?
What version of Drupal are you running?
In the function profile_view_field of profile.module, there is a section that formats the date.
In 4.6.5, it looks like this:
<?phpcase 'date':
list($format) = explode(' - ', variable_get('date_format_short', 'm/d/Y - H:i'), 2);
// Note: we avoid PHP's date() because it does not handle dates before
// 1970 on Windows. This would make the date field useless for e.g.
// birthdays.
$replace = array('d' => sprintf('%02d', $value['day']),
'j' => $value['day'],
'm' => sprintf('%02d', $value['month']),
'M' => _profile_map_month($value['month']),
'Y' => $value['year']);
return strtr($format, $replace);
?>
and in 4.7:
<?php$format = substr(variable_get('date_format_short', 'm/d/Y - H:i'), 0, 5);
// Note: Avoid PHP's date() because it does not handle dates before
// 1970 on Windows. This would make the date field useless for e.g.
// birthdays.
$replace = array('d' => sprintf('%02d', $value['day']),
'j' => $value['day'],
'm' => sprintf('%02d', $value['month']),
'M' => map_month($value['month']),
'Y' => $value['year'],
'H:i' => null,
'g:ia' => null);
return strtr($format, $replace);
?>
It appears it replaces all the tags for the m/d/y/h/i values with its own variables. The 4.6.5 version is lacking the 'H:i' => null line so the H:i tag isn't being replaced(removed, since replaces with null)...and simply gets sent through.
Try adding that line in:
<?php$replace = array('d' => sprintf('%02d', $value['day']),
'j' => $value['day'],
'm' => sprintf('%02d', $value['month']),
'M' => _profile_map_month($value['month']),
'Y' => $value['year'],
'H:i' => null);
?>
Drupal 4.6.6
Drupal 4.6.6, and that section of code in my profile.module looks like:
<?php$replace = array('d' => sprintf('%02d', $value['day']),
'j' => $value['day'],
'm' => sprintf('%02d', $value['month']),
'M' => _profile_map_month($value['month']),
'Y' => $value['year']);
?>
Changing it as you suggest has resolved the issue.