tags:

views:

48

answers:

4

So I am from the UK and have hosting in the US. I contacted my host and said that my server time is set 6 hours behind GMT. They said I need to alter this in my CMS.

How would i go about doing this? Whenever i put now() i am getting the wrong time.

Never seen this before, could anyone offer any suggestions?

A: 

You could work out how many seconds you are in front of the location in the US the server time is set to and add this value to your timestamp to get the correct time.

For example, if the server is in New York then this is 18000 seconds behind London time. So, getting the correct date would be: <?php $now = date('d M Y', (time() + 18000)) ?>

Evernoob
Have you ever had this problem before?Why wont my hosts change the server time!
Luke
probably because it would fuck up the times for other clients with sites on the server.
Evernoob
+3  A: 

You can change the timezone using PHP

putenv("TZ=Europe/London");

or if that produces an error:

date_default_timezone_set('Europe/London');

Alternatively if you can gain access to your php.ini (maybe not due to your hosting)

date.timezone = "Europe/London"

Change the setting to the above and you should be ok. Additional to the above - you can set the php.ini with PHP

ini_set('date.timezone', 'Europe/London');

http://www.php.net/manual/en/timezones.europe.php


Edit:

In my rush to answer - you could write GMT instead of Europe/London

Glycerine
-1 for the `putenv`, `date_default_timezone_set()` is the preferable way of doing this on a per request basis.
Alix Axel
Awesome answer, how would i gain against to php.ini.That last line of code ini_set, where could i put that?In any script that is going to be part of every page?
Luke
You should effectively only need to run `ini_set('date.timezone', 'Europe/London');` once - and it should stick. alternatively I do prefer the `date_default_timezone_set()` just like @Alix said. If you are to set the default time. either use that whenever you need to use dates or put it in a header file which which is shared across your entire website.
Glycerine
GMT is NOT the same as Europe/London. GMT does not include daylight savings (BST), while "Europe/London" does.
AllenJB
It is now updating certain parts, but not all.Just think i need to play around with where to put the code!
Luke
A: 

Use DateTime::setTimeZone to define the timezone. The documentation is in http://www.php.net/manual/en/datetime.settimezone.php

jneves
+1  A: 

For MySQL - you can execute SET time_zone = 'GMT' before your queries to set the time zone time_zone config docs.

For PHP - you can execute date_default_timezone_set() using one of the supported timezones. You could also set the value using a .htaccess directive:

php_value date.timezone UTC
gnarf
+1 for the MySQL solution - I believe that's what the OP is after.
Alix Axel