I'm trying to work with the output from a CCK date field -- trying to format it into a more human-readable format.
(this is a core 5.1 drupal install, using the 5.x-1.2 versions of CCK and Date)
If I do a simple print:
print $item['value']
I get this:
2007-02-22T18:30:00
Which is the correct timestamp, but I would like to have it adapted to our site's time zone (-0600) and formatted a bit better. I read the documentation on the date module, and it looks like I should be able to use the date_show_date function. But when I make this call:
print date_show_date($item['value'], 'm/d/Y H:i', 'local', '')
I get this:
01/01/2007 00:00
It's somehow only managed to get the year. I've checked over my syntax and tried a bunch of variations on the different other attributes, but it just doesn't seem to be working the way I expect it to work. Any clues?
Comments
info on bug; workaround(s)
see this thread for more information about the problem. Seems to be a bug, or at least a problem with the way date is interacting with aspects of cck.
Workarounds
Easy Convert for CCK Date Fields
Assuming that your CCK date field looks like this:
You can format it with this php snippet:
Explained:
date() is a php core function
'M j, Y' is the format string sent to php to tell it how to output the formatted date. See the php date() function for other formats
strtotime() is a php core function
str_replace() removes the "T" in the middle of Drupal CCK's "ISO" date string and replaces it with a space.
$node->field_date[0]['value'] is the var that CCK has in the $node object. The name may be different, depending upon how you named it in your cck types "manage fields" page.
I hope this helps!
Joe
http://www.hydeinteractive.com/
Local News Platform Built on Drupal
http://sanangelolive.com/
madness
Am I the only who thinks this is madness? Why are you talking about workarounds to format a date when using a web framework? All I want is the date in a decent format, this is crazy!