WordPress.org

Ready to get started?Download WordPress

Forums

PHP Function date() being manipulated by WP? (11 posts)

  1. Lucas Martins
    Member
    Posted 4 years ago #

    Since I updated my wordpress installation, the PHP function date is showing the wrong date (now + 2 hours). I tried changing the timezone in the general options, no solution. The server time is correct.

    For example:

    $date = date("G");

    this code on a plugin is returning 19 (wrong date)
    the same code on a separated page (off wordpress system) returns 17 (correct date).

  2. Lucas Martins
    Member
    Posted 4 years ago #

    I commented the line

    add_filter( 'pre_option_gmt_offset','wp_timezone_override_offset' );

    in default-filters.php but no results ... =/

  3. Lucas Martins
    Member
    Posted 4 years ago #

    just found the solution. Commented these lines of wp-settings.php

    if ( function_exists('date_default_timezone_set') )
    date_default_timezone_set('UTC');

  4. mediaseth
    Member
    Posted 4 years ago #

    What does it mean to comment a line? It seems I may have to do that. WP knows the correct time and date, but the front page is five hours off!

  5. levani01
    Member
    Posted 4 years ago #

    I have exactly the same problem, the wordpress time is five hours off!

    Somebody please help!

  6. Rev. Voodoo
    Volunteer Moderator
    Posted 4 years ago #

  7. Maxaud
    Member
    Posted 4 years ago #

    It's not suggested that you edit core code.
    Your changes will be erased upon an upgrade.

    this line checks if date_default_timezone_set is already being used
    if ( function_exists('date_default_timezone_set') )

    You can simply re-define your timezone in your themes functions.php file and it should stop using the one in wp-settings.php

  8. thetooon
    Member
    Posted 4 years ago #

    I think the issue in GMT\server's time difference.

    Could you please check:
    1) What's your real local time and GMT diff;
    2) What's your server's time in operational system;
    3) What's your UTC setting in WP console?

    Like, e.g., for me it is:
    1) 1:41 / +6
    2) 1:41
    3) UTC+6

  9. nootron
    Member
    Posted 4 years ago #

    This is still an active bug in wordpress. It's been hauting me since 2.9 and im frankly surprised at the lack of information regarding the bug, and how to fix it properly.

    To fix it, I would *NOT* recommend editing wp-settings.php. Here's what I did instead. Please offer advice if this is considered a poor fix:

    Add the following to your functions.php file in your theme directory:

    function op_fix_timezone() {
    	date_default_timezone_set('America/New_York');
    }
    add_action('init', 'op_fix_timezone', 1);

    Change the timezone to your own timezone.

    Replace "op" with your own namespace if you wish.

    Notes: I hooked into init, not sure if there's a better tag. Also, I set priority to "1" and I'm not sure if that's a good idea either.

    Cheers

  10. mrmist
    Forum Janitor
    Posted 4 years ago #

    This is not a real bug. Well, it is, but it was only introduced to work around another Not A Real Bug which was the PHP 5.3 requirement to have a default timezone set which some web hosts don't bother to do.

    See http://core.trac.wordpress.org/ticket/10940

  11. stephenju
    Member
    Posted 4 years ago #

    It is a real bug. It broke the blogs that use to display time correctly. And it punishes sites that properly set default time zone.

    Why does it unconditionally set the default time zone instead of only set it when the site doesn't have one?

Topic Closed

This topic has been closed to new replies.

About this Topic