3

In Drupal 7, I have created a node type x, with a date field D:M:Y. Here is an edited Devel tree array structure message for easy reading:

content >> system_main >> nodes >> 31 >> field_Mydate >> #items >> 0 >> value

Main question: How to print the particular node date field value from above extract? (page.tpl)

3

You should use Drupal's 'format_date' function.

Example: format_date(strtotime($entity->field_mydate['und'][0]['value2']) ,'custom','F j, Y');

3
  • I tried printing using the code you suggested but i'm not sure what ['value2'] refers to, or how to fit node id into context. I understand the format_date syntax, but not the middle section. I assumed more details displayed in Devel, would be be used in the code
    – user20154
    Aug 18 '13 at 9:54
  • Value2 is the end date. (Date fields has 2 values in its array). Try using dpm or any other debug method to see the exact structure of the field (from the $content array). By the way, are you adding the above code to your page template?
    – rreiss
    Aug 18 '13 at 11:28
  • thanks, yes this worked with the dpm/devel and I inputed that info into the code. I also realized it only worked if put into node.tpl. cheers. I'll post my results once I am able to post into answers section.
    – user20154
    Aug 18 '13 at 11:44
0

This worked for me:

<?php
print format_date(strtotime($content['field_Mydate']['#items'][0]['value']), 'custom', 'F j, Y'); ?>

I used the format_date function as suggested. I entered the values based on Devel info, and inserted into node.tpl.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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