How to correct timezone

Discussion in 'PHP' started by CuBz, Oct 24, 2007.

  1. #1
    I am gosting with GoDaddy and the time seems to be 2 hour behind,

    I live in UK.

    i tried

    putenv("TZ=Europe/London");
    PHP:
    but that didnt work

    Any ideas?
     
    CuBz, Oct 24, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    
    date_default_timezone_set('Europe/London');
    
    PHP:
    Set this at the top of your script.
     
    nico_swd, Oct 24, 2007 IP
  3. CuBz

    CuBz Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Tried that and i get this...
    
    Fatal error: Call to undefined function: date_default_timezone_set() in /home/content/a/m/a/username/html/includes/functions.php on line 7
    Code (markup):
     
    CuBz, Oct 25, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    You should ask your host to upgrade to PHP 5, since support for PHP 4 is ending this year. (And having this function is really useful too)


    Anyway, there are 2 workarounds now:

    Use date() along with strtotime() to add 2 hours to the current timestamp.
    
    echo date('H:i:s', strtotime('+2 Hours'));
    
    PHP:

    Or:
    Place this once at the top of your script:
    
    setlocale(LC_TIME, 'en_UK', 'english-uk', 'uk', 'eng');
    
    PHP:
    And then use strftime() to format the date.
     
    nico_swd, Oct 25, 2007 IP
  5. CuBz

    CuBz Peon

    Messages:
    117
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5

    But the date function is on at least 50 pages so i wanted a function i could add to the functions page which is included on every page.
     
    CuBz, Oct 25, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Have a look at the control panel of your host. Some of them have an option to switch between PHP 4 and PHP 5. Try enabling PHP 5 if you can. (Then try the first code again)

    Other than that, I don't think there's a way you can change the timezone so that date() displays all dates automatically right.
     
    nico_swd, Oct 25, 2007 IP