0

I've got some nodes which have different time value when I edit and display them.

13th November 2012 6 pm is the value that I input, however, when I tried to display that, it becomes 13th November 2012 7 am. My drupal time zone setting is Australia/Melbourne. When I output the whole array for displaying the time, the time zone value seems to be Australia/Melbourne as well. The array is:

Array ( [0] => Array ([value] => 2012-11-13 07:00:00 [timezone] => Australia/Melbourne [timezone_db] => UTC [date_type] => datetime ))

Has someone got some ideas?

1
  • see the site's timezome setting
    – monymirza
    Nov 20 '12 at 7:30
2

This is why when viewing data out of a Drupal database you should always use the provided wrapper functions. Because the timezone is applied at runtime and not stored in the database, which makes sense because Drupal allows for users to be "part of a timezone" and format their dates based on such.

So for you to get the field rendered just:

render(field_view_field('node', $node, 'field_date_name'));

More on this function can be found here.

2
  • Thanks for your help. I used render(field_view_field('node', $node, 'field_date', array('type' => 'text_long'))); The date value is correct now, however, I could never get the time value. Have you got any ideas of what value to set in the array?
    – Stephen
    Nov 21 '12 at 2:56
  • 1
    Hm strange, I tried it myself and didn't have to pass a formatter type—because it should default to array('type'=>'date_default') but you could try replacing that where you put the 'text_long' Nov 21 '12 at 6:03

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.