Results 1 to 10 of 15

Thread: default timezone

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Dmitriy is offline Nearly a Master Glow Jedi
    Join Date
    Feb 2007
    Location
    Ukraine
    Posts
    124

    Default

    Hey, Scott

    What PHP version we're talking about? I presume PHP5...

    You can try also using
    bool date_default_timezone_set ( string $timezone_identifier )

    Timezones list: PHP: List of timezones in the group America - Manual
    Documentation on your issue: PHP: date_default_timezone_set - Manual

    However, I'd suggest saving all date\time value in UTC & than add timezone offset before the output. This is better than to write to users from Japan that all times are UTC -6 or something like that.

    Let me know how it goes

  2. #2
    Scott's Avatar
    Scott is offline Certified Glow Sage
    Join Date
    Oct 2006
    Posts
    27

    Default

    Alright, I got the php part to work but I am now having trouble with MySQL now().

    Here is the code that I have so far:

    PHP Code:
    echo "<p>PHP 1: ".date("Y-m-d h:i:s")."</p>"// outputs system time, ok

    $q "select now()";
    $r mysql_query($q);
    $d mysql_fetch_assoc($r);
    echo 
    "<p>MySQL 1: ".$d['now()']."</p>"// outputs system time, ok

    putenv("TZ=America/Chicago"); // change php timezone
    echo "<p>PHP 2: ".date("Y-m-d h:i:s")."</p>"// outputs my timezone, ok

    $q "select now()";
    $r mysql_query($q);
    $d mysql_fetch_assoc($r);
    echo 
    "<p>MySQL 2: ".$d['now()']."</p>"// outputs system time, didn't expect this to work for my timezone but why not try

    $q "set time_zone = '-5:00'"// change mysql timezone
    $r mysql_query($q);

    $q "select now()";
    $r mysql_query($q);
    $d mysql_fetch_assoc($r);
    echo 
    "<p>MySQL 3: ".$d['now()']."</p>"// outputs my timezone, ok 
    Per the MySQL docs, I should be able to tell MySQL the timezone that I am in by name, so instead of writing:
    PHP Code:
    $q "set time_zone = '-5:00'"
    I should be able to write:

    PHP Code:
    $q "set time_zone = 'America/Chicago'"
    or:

    PHP Code:
    $q "set time_zone = 'US/Central'"
    However, both of those attempts when using names fail and MySQL complains about them.

    Per MySQL doc:
    Named time zones can be used only if the time zone information tables in the mysql database have been created and populated.

    Can we get these tables loaded or is there another solution to get now() to work as expected?

  3. #3
    Scott's Avatar
    Scott is offline Certified Glow Sage
    Join Date
    Oct 2006
    Posts
    27

    Default

    No takers?
    Am I the only one with this issue?
    What are others doing to work around this?

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14