Results 1 to 7 of 7

Thread: strtotime() problem

  1. #1
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default strtotime() problem

    hi,

    I have the following line:

    echo strtotime("10 September 2000"), "\n";

    If I echo this on one page I get one time and if I echo this on another page I get another time that is an hour ahead of the the other page. I know that this is due to a WordPress include file, but am not sure how they are manipulating the time variable as $SERVER['REQUEST_TIME'] and time() values are unchanged.

    echo strtotime("10 September 2000"), "\n"; takes place after the include.

    any ideas?
    Last edited by james438; 09-16-2010 at 05:21 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

  2. #2
    Join Date
    Nov 2006
    Location
    Northeast USA
    Posts
    408
    Thanks
    8
    Thanked 30 Times in 28 Posts

    Default

    Are you sure it is an hour? the milliseconds can be deceiving if you don't convert them back right. It could just be the difference from when you did one test and when you did the second.
    -Ben -- THE DYNAMIC DRIVERS
    My Links: My DD Profile||My Youtube Video Tutorials||DD Helping Coders||DD Coders In Training
    I told my client to press F5, the client pressed F, then 5, *facepalm*

  3. #3
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    if I compare the time in seconds from one page to the next it is off 3600 seconds, which is why I add 3600 seconds to equal the two pages out.

    Code:
    echo "<br>$_SERVER[REQUEST_TIME]<br>";
    $_SERVER['REQUEST_TIME']=time()+3600;
    echo "$_SERVER[REQUEST_TIME]<br>";
    print time();
    $starttime = strtotime("$qdate");
    echo"<br>$starttime";echo "<br>$qdate";
    on test1.php where the WordPress include is used I get the following:

    1284605171
    1284608772
    1284605172
    1282953600
    28 August 2010

    on test2.php I get:

    1284605149
    1284608749
    1284605149
    1282975200
    28 August 2010

    I am not sure how to reproduce this when the WordPress include is not present.
    To choose the lesser of two evils is still to choose evil. My personal site

  4. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Clarify: on test2.php, Wordpress is not involved?

    I don't use Wordpress, but I based on other CMSs, I would suspect some sort of timezone function. test1 would be using the Wordpress-configured timezone, and test2 would be using your server's default timezone.

    ...?

  5. #5
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    On test2.php WordPress is not involved.

    I agree that WordPress is manipulating the timezone, but I seem unable to replicate this in order to fix the problem. Actually, I plan on creating a better workaround if I can figure out what they are doing.

    P.S. Congrats on making it to Elite Coder
    To choose the lesser of two evils is still to choose evil. My personal site

  6. #6
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,643
    Thanks
    63
    Thanked 516 Times in 502 Posts
    Blog Entries
    5

    Default

    Quote Originally Posted by james438 View Post
    P.S. Congrats on making it to Elite Coder
    ha! I didn't even know what you were talking about
    had to look around

    maybe a WP forum would be a better place to find a solution?

  7. #7
    Join Date
    Jan 2007
    Location
    Davenport, Iowa
    Posts
    2,385
    Thanks
    100
    Thanked 113 Times in 111 Posts

    Default

    Maybe, but I think that this involves the strtotime() function. In the examples listed above I manipulated the $_SERVER['REQUEST_TIME'] and printed the time() values as well as the unmanipulated $_SERVER['REQUEST_TIME'] and the $qdate value and as you can see they are unchanged from page 1 to page 2 just as it should be, but strtotime() seems to think that the current UNIX timestamp is different depending on the page. I am using php 5.2.8. This means to me that somehow the UNIX timestamp is being manipulated, but not by any method I am familiar with.

    If I find the answer I'll try to post something here.

    Code:
    echo date_default_timezone_get() . ' => ' . date('e') . ' => ' . date('T');
    Will echo
    Code:
    UTC => UTC => UTC
    on a WordPress included page and
    Code:
    America/Denver => America/Denver => MDT
    on a non WordPress page.

    EDIT: Solved it.

    Code:
    date_default_timezone_set('America/Los_Angeles');
    will set the timezone to the correct timezone. The UTC value is pulled from many available sources and when none is available or the value is not formatted correctly you will get a UTC printed out as demonstrated above. Now to set it to Iowa/Illinois time where I live. I am not sure what happens with daylight savings time though, but I'll worry about that then, if it ever comes up.
    Last edited by james438; 09-16-2010 at 07:15 PM.
    To choose the lesser of two evils is still to choose evil. My personal site

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
  •