4

I use the Date Module. My contenttype event dates are stored like

field_date['de'][0]['value'] = 2011-12-09T10:40:00 (String, 19 characters )
field_date['de'][0]['value2'] 2011-12-09T13:10:00 (String, 19 characters )
field_date['de'][0]['timezone'] Europe/Berlin (String, 13 characters )
field_date['de'][0]['timezone_db'] UTC (String, 3 characters )
field_date['de'][0]['date_type'] (String, 4 characters ) date | (Callback) date();

How to apply my timezones to the values? When I edit the date on my field_date and also when my dates are displayed, everything is fine. But I have to work with the raw DB values and need to apply the timezone. Doing it by hand with php +1h should work, but then it's summertime again....

11

This took me a hot minute to figure out... Use the format_date function, but be sure to specify how the date is stored in the db - usually UTC, and then offset by your date field's stored timezone - usually your drual admin specified default timezone.

foreach ($node->field_date['und'] as $date) {
  $unixdate = strtotime($date['value'].' '.$date['timezone_db']);
  print format_date($unixdate,'medium','',$date['timezone']);
}
1

I had the same problem but in Drupal 6. I found http://drupal.org/node/295105#comment-1969952 which has a nice function to do this, and it looks like there is a Drupal 7 version as well http://drupal.org/node/295105#comment-4884180 although I haven't tested it personally.

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.