Jump to content

Php timezone set question


Recommended Posts

So I am using a free host that I am completely happy with, but it's server time is wrong. Four hours off to be exact. For instance, on my forum (phpBB3) which I am testing now has the wrong time. Users have to have their timezone set to UTC-3 to be correctly displayed UTC-7. Also, at the bottom of the board pages it says "all times are UTC-3" even though they are UTC-7.So what I'm wondering is, is there any way to change how PHP accesses the time. Basically can I put in some code that will tell PHP that my server's time is off or something like that so it can adjust. But I don't really know, so any solution would be great.Any help is much appreciated. :)**Sean

Link to comment
Share on other sites

What function is used to display the time? Can we see its source?
The forum is the standard phpBB3, latest stable release. I'll look through it and post again.
You can change the default timezone per script:http://www.php.net/manual/en/function.date...imezone-set.php
I saw this before and was wondering if it would work or not. So would this actually change the timezone php reads? Like if the server says it's 7:00 (UTC time) and you set the default timezone to UTC-4 or something, does it then assume 7:00 is actually UTC-4?Or, as I'm guessing, does it still assume the server time is correct UTC and just makes it a default to display the time 4 hours off. If the second is the case, I don't think it would fix the error, as I'm pretty sure (and I'll check on this) that the forum changes the default timezone for a user the same way (the same function) which would then have the same error. Also, it might post the bottom "all time is UTC-4" post through that value as well. Although, I am unsure.I'll look into this a bit more soon and post again with more info that might help.Thanks for both of your help! Any more input is appreciated! :)
Link to comment
Share on other sites

So I am using a free host that I am completely happy with, but it's server time is wrong. Four hours off to be exact.
Their time isn't wrong, that time is where the server is found, in order to display the correct time you must use th following code, according to where you are of course, but remember this is only set for within the script, it you close this script '?>' and have something else like some mark up, and then re open a php script on the same page '<?php' then this default time no longer applies
date_default_timezone_set('Europe/Paris');print date ('l F jS Y');

If you're using the datetime in a database on a server that has a different time zone, then to retreive your time, you must add or substract a certain amount of hours to get the time correct in your sql

SELECT *, DAYOFMONTH(ADDDATE(registration_date, INTERVAL 9 HOUR)) AS day, MONTH(ADDDATE(registration_date, INTERVAL 9 HOUR)) AS month, YEAR(ADDDATE(registration_date, INTERVAL 9 HOUR)) AS yearFROM users

using the ADDDATE(value, INTERVAL ... hours)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...