Support » Fixing WordPress » wordpress affecting time() function

  • Resolved deko


    I have a PHP script that is called in the footer of my blog pages and also at the end of a few stand-alone pages. The exact same script runs, but when called from the blog footer, it returns a different value than it does from the stand-alone pages. The script uses time() to get a time value.

    The output below is what I am seeing. The 9:41 time is correct and is returned by the script when called from the stand-alone (non-blog) pages. The 4:41 time is 7 hours ahead of the server’s local time (which is 9:41) and is returned when the script is called from the blog pages.

    Is there some function WordPress uses that resets the time to UTC? If so, how do I circumvent this so my script returns the correct local time?

    I’ve tried modifying the time zone in wp-admin > Settings > General Settings but it makes NO DIFFERENCE which timezone I select. The time my script returns is consistently 7 hours ahead – and consistently correct when called from non-blog pages.

    May 24 2012 09:41 pm
    May 24 2012 09:41 pm
    May 24 2012 09:41 pm
    May 25 2012 04:41 am
    May 25 2012 04:41 am
    May 25 2012 04:41 am

Viewing 3 replies - 1 through 3 (of 3 total)
  • WPyogi


    Forum Moderator

    Have you looked at the Codex info on time/date? PHP does have a bunch of built-in time/date functions, so it’s likely something is different in those two locations as to how the date is displayed…

    <?php get_the_time( $d, $post ); ?>

    Returns the time of the current post for use in PHP. It does not display the time.


    So do I have to unravel whatever get_the_time is doing? Is there some function I can run, before my script runs, that will reset PHP so it will return the expected value from time()?

    I revised the first lines of my script to this:

    $timestamp = time();

    This fixed whatever WordPress did that made the PHP time() function return a value different from what time() would get from non-wp pages.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘wordpress affecting time() function’ is closed to new replies.