Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Choosing & Storing Timezones

4:24 am on Jun 14, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Mar 20, 2008
posts: 172
votes: 0

Hi all,

So I am storing some datetime values in a MySQL db. I am setting the values as the current time according to whatever time it is in UTC (GMT +0). What I want to do is have the user set their timezone i.e Australia/Brisbane, and then the datetime which was stored in UTC time, would display the datetime of that timezone. In the case of this example, we would see:

UTC: 2010-06-14 01:00:00 (GMT + 0:00)
Australia/Brisbane: 2010-06-14 11:00:00 (GMT + 10:00)

I am setting the timzones using the putenv function, but am unsure how to changes a timezone I know was stored in UTC.

Your help would be greatly appreciated.

4:28 am on June 14, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Mar 20, 2008
votes: 0

So to clarify, the database would hold:

2010-06-14 01:00:00 (UTC: GMT + 0:00)

..and the front end of the website would show:

2010-06-14 11:00:00 (Australian/Brisbane: GMT + 10:00)
5:44 pm on June 16, 2010 (gmt 0)

Junior Member

5+ Year Member

joined:Nov 14, 2006
votes: 0

I use something similar to this function:

## function offset_date
## format; same as php function date
## offset; offset seconds; ie: GMT+3 3*60*60
function offset_date($format, $unix_timestamp, $offset=0) {
$unix_timestamp = empty($unix_timestamp) ? time()+$offset : $unix_timestamp+$offset;
return @gmdate($format, $unix_timestamp);

Since your times are in ISO format, you probably find this function handy:
function ISOdate2UNIXtime($ISOdate) {
return gmmktime(substr($ISOdate,11,2),substr($ISOdate,14,2),substr($ISOdate,17,2),substr($ISOdate,5,2),substr($ISOdate,8,2),substr($ISOdate,0,4));
8:21 pm on June 16, 2010 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
votes: 0

Do you allow for changes caused by DST? You might need a toggle to allow for that.

New York is UTC-0500 in their Winter, and UTC-0400 in their Summer.

Southern Hemisphere winter occurs during Northern Hemisphere summer, and vice versa.

The UK uses UTC+0000 in their Winter and UTC+0100 in their Summer.

I would completely avoid the term "GMT". It was replaced by UTC in 1972.

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members