Title: PHP Function date() being manipulated by WP?
Last modified: August 19, 2016

---

# PHP Function date() being manipulated by WP?

 *  [Lucas Martins](https://wordpress.org/support/users/lucasms/)
 * (@lucasms)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/)
 * 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).

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Thread Starter [Lucas Martins](https://wordpress.org/support/users/lucasms/)
 * (@lucasms)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1354888)
 * I commented the line
 * add_filter( ‘pre_option_gmt_offset’,’wp_timezone_override_offset’ );
 * in default-filters.php but no results … =/
 *  Thread Starter [Lucas Martins](https://wordpress.org/support/users/lucasms/)
 * (@lucasms)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355067)
 * just found the solution. Commented these lines of wp-settings.php
 * if ( function_exists(‘date_default_timezone_set’) )
    date_default_timezone_set(‘
   UTC’);
 *  [mediaseth](https://wordpress.org/support/users/mediaseth/)
 * (@mediaseth)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355123)
 * 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!
 *  [levani01](https://wordpress.org/support/users/levani01/)
 * (@levani01)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355131)
 * I have exactly the same problem, the wordpress time is five hours off!
 * Somebody please help!
 *  [Rev. Voodoo](https://wordpress.org/support/users/rvoodoo/)
 * (@rvoodoo)
 * [16 years, 4 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355132)
 * [http://codex.wordpress.org/Commenting_Code](http://codex.wordpress.org/Commenting_Code)
 *  [Maxaud](https://wordpress.org/support/users/maxaud/)
 * (@maxaud)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355139)
 * 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
 *  [thetooon](https://wordpress.org/support/users/thetooon/)
 * (@thetooon)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355146)
 * 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
 *  [William](https://wordpress.org/support/users/nootron/)
 * (@nootron)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355153)
 * 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](http://www.php.net/manual/en/timezones.php).
 * 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
 *  [mrmist](https://wordpress.org/support/users/mrmist/)
 * (@mrmist)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355154)
 * 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](http://core.trac.wordpress.org/ticket/10940)
 *  [stephenju](https://wordpress.org/support/users/stephenju/)
 * (@stephenju)
 * [16 years, 3 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355155)
 * 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?

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘PHP Function date() being manipulated by WP?’ is closed to new replies.

## Tags

 * [date](https://wordpress.org/support/topic-tag/date/)
 * [timezone](https://wordpress.org/support/topic-tag/timezone/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 10 replies
 * 9 participants
 * Last reply from: [stephenju](https://wordpress.org/support/users/stephenju/)
 * Last activity: [16 years, 3 months ago](https://wordpress.org/support/topic/php-function-date-being-manipulated-by-wp/#post-1355155)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
