bsgrules wrote:When developing a site where people can set their local timezones...What is the most efficient way to manage something like this?
Should I store the dates in mysql datetime format and always open a connection with their local timezone set like so.
set time_zone = '-6:00';
Is this what everybody does or do some people actually use unix timestamps for this?
I've also heard of people just storing all time as GMT and how can I automatically detect whether the user is observing daylight savings or not.
A few points. Storing the user's timezone is probably most efficient. However, determining their timezone automatically is not so simple. You can sometimes get it with javascript and computing the offset to make a best guess.
However, offset <> timezone. For instance, some cities on Central time don't observe daylight savngs. So, for one part of the year they'll be the same offset as, say, Chicago, and for the other part, they won't.
There are two ISO standard types to deal with here, timestamp with timezone, and timestamp (without timezone, natch).
Now, the weird thing is that the way the timestamp with timezone (hereafter referenced as timestamptz) works is that it comes in with a timezone or offset, and the db converts it to GMT and stores that, and then throws away the timezone itself.
So, if you want to store a timezone to go with your timestamp, you have to rip it off in your app and store it in a separate field, then set the connection timezone to the same as your user using that, then retrieve the timestamp to get it converted back to the right timezone.
I'm not as familiar with MySQL's timestamptz type behaviour. I'm a pgsql guy as you can tell by my sig. But I am very familiar with making tz stuff work, and can tell you it's sadly not as simple as an offset...