We created several hundred nodes, a custom content type 'event' for an event calendar, before we set a time zone for our site.

Since we did not have a time zone set, all our log messages were off by 6 hours. So, I set the proper time zone.

As you might imagine, all the events were suddenly off by a large differential, I think 7 hours.

So, does anyone have suggestion on how I might fix my data. Do I need to work out a sql statement that will add the proper amount of hours to each date field to match the desired time zone?

Comments

karens’s picture

The exact way to fix this will depend on what kind of date you are using, and whether or not you have dates that use different offsets (like when some are before and others after a change in daylight savings time), and what kind of timezone handling you are using.

Almost anything I can think of would be fairly complicated to do in SQL. I think it would be easier to write a small custom PHP script like the following. You'll have to play around with it to see exactly what gives you the right results:

$result = db_query("SELECT nid FROM {TABLE} ORDER BY nid");
while ($row = db_fetch_array($result)) {
  $node = node_load($row['nid']);
  $date = date_make_date($node->FIELD_NAME[0], DB_TIMEZONE, DATETYPE);
  date_modify($date, '+7 hours'); // Or whatever adjustment you find is needed.
  node_save($node);
}

Where
- TABLE is the table where your date data is stored,
- FIELD_NAME is the name of your field,
- DATETYPE is the type of date, 'date', 'datestamp' or 'datetime',
- DB_TIMEZONE is the timezone the data got stored as originally (UTC if you're using the site timezone, that bad timezone if you're using no timezone handling)

karens’s picture

And then empty the cache_content table after you finish doing this or you'll keep seeing the old, cached values of the nodes.

justageek’s picture

Thanks much. We are not doing anything special with daylight savings time, and the users are just using the nice calendar widget to select a date and time in two date fields. So, I just need to figure out how much time is added when I turn on the correct time zone, then use your php script to adjust the other direction.

Thanks again!

karens’s picture

Status: Active » Fixed

I see I missed a step above. I created a date but didn't update the node value. You'll need to update $node->FIELD_NAME[0]['value'] and $node->FIELD_NAME[0]['value2'] with the new date before saving the node.

Status: Fixed » Closed (fixed)

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