I have a date that reads 18 Nov 2011 (all day) in my date field in the edit form. It also displays correctly when i use this code:
print render($content['field_course_date']);
but as i want to manipulate the date i've tried using the code on the front page of this module and get the wrong date.
Here's the code i've used:

$date = new DateObject($node->field_course_date['und'][0]['value'], date_default_timezone(), DATE_FORMAT_ISO);
debug($date);
print $date->format('d');

This will print out 17 rather than 18. In the database the date is stored like this: 2011-11-17T23:00:00, so it seems the timezone conversion isn't working as i want it to.
My region default timezone is set to Europe/London, my server is in the states, the debug output above is as below:

DateObject::__set_state(array(
   'granularity' => 
  array (
    0 => 'hour',
    1 => 'minute',
    2 => 'second',
    3 => 'month',
    4 => 'day',
    5 => 'year',
    6 => 'timezone',
  ),
   'errors' => 
  array (
  ),
   '_serialized_time' => NULL,
   '_serialized_timezone' => NULL,
   'timeOnly' => false,
   'dateOnly' => false,
   'date' => '2011-11-17 23:00:00',
   'timezone_type' => 3,
   'timezone' => 'Europe/Berlin',
))

I've no idea why Europe/Berlin appears as the timecode here. It may also be relevant that we are in daylight saving time in Britain (where i'm based and have my timezone set) right now, which meant the clocks went forward an hour.

Comments

amcc’s picture

In my regional settings I unchecked "Users may set their own time zone." and found that the times had changed for that date field by 1 day back. I then resaved them as they should be, now everything is working as normal.

I am a little confused as to how Europe/Berlin got set as my admin user timezone, it is certainly not something I would do. Perhaps the fact that daylight saving time is the same as the +1hr in berlin caused something to happen automatically.

karens’s picture

Status: Active » Fixed

So this is fixed. Obviously the Date module did not change your admin user timezone, so it looks like it is not a Date problem.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.