0

So I have made something ridiculously complicated by accident because I don't think you can have individual timezones per database in MySQL if they're on the same account?

Basically most of my databases are for American users and use one of the American timezones, I then also run an English blog.

My issue is that the English blog has the correct BST (GMT+1) value inserted into the datetime row but it's in the database that uses the MDT timezone.

I then need to get that time for an rss feed using:

$date = date('r', $data['date']); //MDT system but $data['date'] is GMT+1

but this gives me a time in the future at the time of the blog post due to incorrect timezone.

Is there a way I can convert BST to MDT?

but it gets even more complex because some months of the year in England we use GMT (GMT+0) instead of BST (GMT+1) ... is there anyway to work out which timezone is being used in England at the time of year and do a conversion or am I just way overcomplicating this whole matter?

Dan
  • 11,914
  • 14
  • 49
  • 112
  • The easiest method is to store all times in UTC and just display in the relevant timezone when it is displayed. That way you can display in multiple timezones as required and always have one reference time in the db which is easy to convert to any TZ – Anigel Jul 31 '13 at 11:09
  • @Anigel trouble is I have 6+ years worth of data now so it's not very easy to change that – Dan Jul 31 '13 at 11:11
  • 1
    The answer here may help http://stackoverflow.com/questions/13698779/timezone-with-dst-handling-by-php – Anigel Jul 31 '13 at 11:14

1 Answers1

0

The following solution works perfectly:

$oldDate = date('l F j Y H:i:s', $link['date']);
$date = new DateTime($oldDate, new DateTimeZone('Europe/London'));
$date->setTimezone(new DateTimeZone('UTC'));
echo $date->format('r');
Dan
  • 11,914
  • 14
  • 49
  • 112