tags:

views:

64

answers:

3

I am creating a script that allows the user to choose their own timezone...

If I am to make this work, how do I store dates in the database so that every timezone will read it, and show the correct date in their timezone?

Do I store the date as GMT and then when a user with the timezone GMT +10 selected views the item within my script, I show that date in GMT +10 time?

Is there a better way to do this?

Examples would be great :)

+3  A: 

Storing the timezones in UTC in the database is definitely the way to go.

Mark Byers
+1  A: 

UTC is how you do it

Get a current date from their browser (use Javascript and post the browsers date to the server) to work out what time zone they are in and set it as a default

TFD
+1  A: 

In MYSQL, Timestamp fields are always saved internally in UTC, but queries will return formatted strings based on the timezone of your database server, so your db server should probably be set to UTC to simplify things. Pass that stuff straight into a DateTime object, then you can use it's setTimezone() function to make it operate in the timezone you want.

You can also use date_default_timezone_set() to set a timezone in php, which will be used for the remainder of your script.

keithjgrant
Oh, and "UTC" is the new "GMT", just for clarification.
keithjgrant