Jump to content

Recommended Posts

My original server was based in England and i completely missed the fact that different people in different time zones will be stuck with the wrong times.

As a result i am creating a function to wrap around all of the postdates. i.e. timezone($time)

I have this so far

[code]function timezone() {

$timezone = $userdata['user_timezone'];
$serverTime = "1.0";
$difference = ($serverTime - $timezone);

}[/code]

The database stores timezones in decimal format. So GMT is 0.0, GMT+1 is 1.0.

The $difference generates what needs to be subtracted from the time to get to the users time zone. So...
GMT would give you.

1.0 - 0.0 = 1.0. Time - 1.0 will get you to the GMT.

As for the final step. How do i add the time aspect to add/subtract the $difference variable?
Something like:

[quote]
$databaseTime = get_your_database_time_you_want_to_change();  //databaseTime now has the time you want to manipulate
$timestamp = strtotime($databaseTime);  //turns a string into a timestamp

$timestamp -= ($difference * 360); //there are 360 seconds in an hour... so if $difference is a number of hours, this will subtract the right number of seconds off of $timestamp

$ourTime = date('Y-d-m h:i:s',$timestamp); //you might wanna double check the format I have it (the Y-d-m h:i:s), but that'll put it back into the format the DB likes

//no update your database

[/quote]
[quote author=Deltran link=topic=123533.msg511773#msg511773 date=1169587739]
Something like:

[quote]
$databaseTime = get_your_database_time_you_want_to_change();  //databaseTime now has the time you want to manipulate
$timestamp = strtotime($databaseTime);  //turns a string into a timestamp

$timestamp -= ($difference * [b]3600[/b]); //there are [b]3600[/b] seconds in an hour... so if $difference is a number of hours, this will subtract the right number of seconds off of $timestamp

$ourTime = date('Y-d-m h:i:s',$timestamp); //you might wanna double check the format I have it (the Y-d-m h:i:s), but that'll put it back into the format the DB likes

//no update your database

[/quote]
[/quote]

There are 3600 seconds in an hour (60 * 60). Make sure you get the right values or the time might be off by alot
[quote author=TheWandererLee link=topic=123533.msg511778#msg511778 date=1169588016]
There are 3600 seconds in an hour (60 * 60). Make sure you get the right values or the time might be off by alot
[/quote]

And I typed that [b]twice[/b]...  I'm so sorry.  :(
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.