views:

289

answers:

2

I have an application that stores GMT time data in a MySQL db like this: 2009-12-16 15:27:47.

The user's timezone offset is stored in another column like this: -6

The above timezone is GMT-6, which is CST. Is there any way I can echo CST (i.e. - date('T")) from the GMT offset data?

Note: I should also add that the application global timezone is set using: date_default_timezone_set('GMT');

A: 

Try this: http://php.about.com/b/2007/09/12/adding-and-subtracting-time.htm.

Cryophallion
That doesn't help with displaying the timezone.
Jordan Ryan Moore
Also, downvoted for about.com spam
metrobalderas
A. I was focusing on the correct time output.B. Who cares what the source is? It was a valid answer. Basically you wouldn't have downvoted me if I had copy/pasted?C. The first part I figured he had (the timezone from his db), and he knew the list of time zones.
Cryophallion
+1  A: 

Unfortunately, there isn't always a single timezone for each GMT offset. Many GMT offsets have multiple timezones. Also, GMT offsets change during DST (where applicable). For instance, during DST, US/Arizona and US/Mountain share the same GMT offset; however, during the rest of the year, US/Mountain and US/Arizona don't share the same GMT offset. You can either use DateTimeZone::listIdentifiers() or check out the manual for a list of supported timezones in PHP.

If you were starting an application from scratch, I would suggest storing the timezone identifier instead of the GMT offset, but I'm guessing your application is already in production. In that case, there's not really a reliable way to display the timezone without improving your data.

I would suggest that you add a timezone column to the table. You could write a one-time script that would set the timezone to some pre-defined list of defaults based on the GMT offset. For instance, if the GMT offset is 8, set the timezone to America/Los_Angeles. Finally, change your application to display/save timezone identifiers instead of GMT offsets. This may cause problems for a subset of your users, but it allows them to change their timezone if they need to.

Jordan Ryan Moore
Ok, thanks for the info.
Josh