I have an imagefield, 'event_image' and printing all possible variables for the field tells me I have timestamp as a possible variable of the image to render. I use:
print '<pre>';
var_dump(get_defined_vars());
print '</pre>
// renders:
["timestamp"]=>
string(10) "1348629688"
... in node--mycustom.tpl.php
to get the variables.
Now I can render the timestamp as such:
<?php print $node->field_event_image['und'][0]['timestamp'] ?>
... and it prints a UNIX formatted timestamp as:
1348629688
I'd like to convert this to a PHP date format. So I am guessing I would need to convert the UNIX timestamp somehow using the PHP gmdate
function. Typically I would use something like this for raw php:
$mytimestamp=1348629688;
print gmdate("m-d-Y", $mytimestamp);
Which would take my timestamp and output:
09-26-2012
... but I just don't know how to do within the context of my drupal 7 field and the node template.
UPDATE:
Base on clive's comment below, it turns out a preprocess function is the way to go: So in my theme's template.php file I now have:
function MYTHEME_preprocess_node(&$vars, $hook) {
$node = $vars['node'];
$field_items = field_get_items('node', $node, 'field_event_image');
$vars['upload_date'] = format_date($field_items[0]['timestamp'], 'mdy');
}
... and then in my custom node template, I have:
<?php print $upload_date; ?>
Note, 'mdy'
is a custom format I set in the Drupal UI. That's better than using gmdate
I suppose.