Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    I'm getting puzzling results from PHP's date function, and I wonder if someone can explain why.

    I'm running PHP 5.2.4 with Windows XP.

    I'm in the USA's Pacific Time Zone. Right now we're on Daylight Savings Time, and our current time is 7 hours behind GMT.

    When I encountered this problem, Windows said the local time is 10:50 AM, which was correct. So did MySQL when I executed the query SELECT NOW().

    The date_default_timezone_get function returned "Etc/GMT-5".

    When I executed this statement:

    Code:
    $TimeStamp = date('Y-m-d H:i:s',time() );


    I should have gotten the current local time in formatted form, for example, "2010-10-16 10:50:00"

    Instead I got "2010-10-16 22:50:00" -- 12 hours late.

    I've tried several variations of this, such as omitting the time() parameter, converting to 12-hour time, etc. I always get the same thing.

    When I execute the same code on my client's host (PHP 5.2.14 under Linux) I get the right answer.

    Is this a known problem with particular versions of PHP, or with Windows? Is there a workaround?

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    I don't know whether this is OS-related, but is it possible to develop on 5.2.14 on Windows? There may be other little differences that are less visible...

  3. #3
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    It's possible, and probably desirable, but I've learned to approach software changes with caution. They don't always produce the desired results, and they're not always reversible, even when they're supposed to be.

    On another machine I'm evaluating an updated suite of development tools that will include a new version of PHP. I'll make this one of the tests I perform on it.

    Meanwhile, I'll welcome any other suggestions.

  4. #4
    New Lounger
    Join Date
    Jan 2010
    Location
    London
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just to check that it says Etc/GMT-5 and not GMT+5, or that would account for the 12 hours (7+5) (or double check with the O parameter to see which one the date function is using)?

  5. #5
    4 Star Lounger
    Join Date
    Mar 2002
    Location
    Sacramento, California, USA
    Posts
    509
    Thanks
    4
    Thanked 1 Time in 1 Post
    Over the past couple of months I did enough preliminary testing to feel safe putting PHP 5.2.14 on my development system. I retested this problem, and it has gone away.

    It might have been a release dependent problem in PHP, or just a bit of weirdness with no logical explanation. Whatever, it's gone.

Posting Permissions

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