I want to print "event_info_date" Date (Unix timestamp) field with custom format in node.tpl.php.

I'm using this code:

<?php print date("Y/m/d h:i:s", $node->event_info_date['und'][0]['value']); ?>

And it prints: 1970/01/01 01:00:00, but it isn't value from my field.

I've also tried this:

<?php print format_date($node->event_info_date['und'][0]['value'], 'custom', 'Y/m/d h:i:s'); ?>

But it doesn't print anything. Any ideas?

  • So, based on what I see here, it's not the date() function, but the value in the second argument. It must not be returning a valid date because it's printing essentially the first date. Any more code to assist? Are you doing this in a hook? Also, pedantically, I recommend LANGUAGE_NONE rather than 'und' Commented Sep 30, 2015 at 0:10

1 Answer 1


Try this:

print date("Y/m/d h:i:s", strtotime($node->event_info_date['und'][0]['value']));

Hope this will help you.

  • This code is printing this: 1970/01/01 01:00:00, while the value of the field is: 2015/09/30 00:56:00
    – user504944
    Commented Sep 30, 2015 at 20:17
  • can you send me the exact value you are getting in this: "$node->event_info_date['und'][0]['value']". you can do this by : drupal_set_message($node->event_info_date['und'][0]['value']); or direct print.
    – S Singhal
    Commented Oct 1, 2015 at 4:04
  • One more thing if you're not getting any value in this that means either you array structure is not proper, so try this one to get the structure: drupal_set_message(print_r($node->event_info_date,1));
    – S Singhal
    Commented Oct 1, 2015 at 4:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.