Perad Posted January 22, 2007 Share Posted January 22, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/35249-having-trouble-getting-going-on-a-time-function/ Share on other sites More sharing options...
Perad Posted January 22, 2007 Author Share Posted January 22, 2007 Sorry can't find edit button. Thought i should mention that times being changed are using the postdate database type. Quote Link to comment https://forums.phpfreaks.com/topic/35249-having-trouble-getting-going-on-a-time-function/#findComment-166527 Share on other sites More sharing options...
Daniel0 Posted January 22, 2007 Share Posted January 22, 2007 You need to declare the $userdata as global:[code]function timezone() {global $userdata;$timezone = $userdata['user_timezone'];$serverTime = "1.0";$difference = ($serverTime - $timezone);}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/35249-having-trouble-getting-going-on-a-time-function/#findComment-166550 Share on other sites More sharing options...
Perad Posted January 23, 2007 Author Share Posted January 23, 2007 Ah thanks for that, i missed that.My question was more towards how i actually subtract the time from the database entry.How do i subtract 1.0 (1 hour) from 2007-01-22 01:44:06? Quote Link to comment https://forums.phpfreaks.com/topic/35249-having-trouble-getting-going-on-a-time-function/#findComment-167174 Share on other sites More sharing options...
Perad Posted January 23, 2007 Author Share Posted January 23, 2007 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/35249-having-trouble-getting-going-on-a-time-function/#findComment-167558 Share on other sites More sharing options...
Deltran Posted January 23, 2007 Share Posted January 23, 2007 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 Link to comment https://forums.phpfreaks.com/topic/35249-having-trouble-getting-going-on-a-time-function/#findComment-167581 Share on other sites More sharing options...
TheWandererLee Posted January 23, 2007 Share Posted January 23, 2007 [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 Link to comment https://forums.phpfreaks.com/topic/35249-having-trouble-getting-going-on-a-time-function/#findComment-167586 Share on other sites More sharing options...
Deltran Posted January 23, 2007 Share Posted January 23, 2007 [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. :( Quote Link to comment https://forums.phpfreaks.com/topic/35249-having-trouble-getting-going-on-a-time-function/#findComment-167593 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.