SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    PHP Time zone problem is killing me

    Hai folks,

    i am running wamp server on my windows7 laptop.

    php.ini

    Code:
    [Date]
    ; Defines the default timezone used by the date functions
    ; http://php.net/date.timezone
    date.timezone = Asia/Riyadh
    my script

    Code:
    date_default_timezone_set('Asia/Riyadh'); 
    putenv("TZ=Asia/Riyadh"); // i put this also since previous one also not correctly showing..
    echo date('Y-m-d H:i:s');
    php shows wrong date. it says 2012-05-05 02:49:58
    but its now 2012-04-05 16:53:20 here in Riyadh.

    whats wrong. i restarted several times the server also .

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php 
    $timezone 
    "Asia/Riyadh"
    if(
    function_exists('date_default_timezone_set')){
      
    date_default_timezone_set($timezone); 
    }else{
      echo 
    '********* ZONE NOT SET **********';
    }

    mysql_query("SET SESSION time_zone = '+3:00'"); 
    ?>
    apparently MySQL doesnt support Asia/Riyadh hence the seperate setting for your database
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    PHP Code:
    <?php 
    $timezone 
    "Asia/Riyadh"
    if(
    function_exists('date_default_timezone_set')){
      
    date_default_timezone_set($timezone); 
    }else{
      echo 
    '********* ZONE NOT SET **********';
    }

    mysql_query("SET SESSION time_zone = '+3:00'"); 
    ?>
    apparently MySQL doesnt support Asia/Riyadh hence the seperate setting for your database
    Thank you for the reply.
    i did exactly as shown above.
    unfortunately still shows the wrong date


    Code:
    <?php 
    $timezone = "Asia/Riyadh"; 
    if(function_exists('date_default_timezone_set')){
      date_default_timezone_set($timezone); 
    }else{
      echo 'Warning! Time zone not correctly set.';
    }
    
    mysql_query("SET SESSION time_zone = '+3:00'"); 
    ?>
    Code:
    echo date('Y-m-d H:i:s');
    2012-05-05 05:48:20

  4. #4
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    I assume that the time and date are set correctly on the machine your running Wamp on

    I know, but Ive gotta ask
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  5. #5
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mandes View Post
    I assume that the time and date are set correctly on the machine your running Wamp on

    I know, but Ive gotta ask
    yes mandes, its correctly set.

    when i mouse over system tray clock it shows Friday, May 4 2012

    btw, i put back the php.ini to its default : date.timezone = UTC

  6. #6
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    btw, current date and time in riyadh for your referrence
    Friday, May 4, 2012 at 8:19:32 PM AST
    http://www.timeanddate.com/worldclock/city.html?n=214


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •