Title: Problems with timezone when using new function wp_date()
Last modified: November 20, 2019

---

# Problems with timezone when using new function wp_date()

 *  Resolved [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/problems-with-timezone-when-using-new-function-wp_date/)
 * Hi,
 * Because of the new function [wp_date()](https://developer.wordpress.org/reference/functions/wp_date/)
   I have updated the date fields of my events plugin, but run into a timezone problem.
   In some cases the wrong day is being returned. Depending on the timezone.
 * I simply replaced all occurences of `date_i18n()` with `wp_date()`. Example:
   
   This:
 *     ```
       date_i18n( $dateformat, esc_attr( $date ) )
       ```
   
 * Became this:
 *     ```
       wp_date( $dateformat, esc_attr( $date ) )
       ```
   
 * But I now notice there’s a [third parameter](https://developer.wordpress.org/reference/functions/wp_date/#parameters),
   called $timezone, so I thought adding the default value `null` fixes my problem.
   But no change, because `null` seems to be the PHP `time()`.
 * Who can tell me how to fix this? No timezone should be added when outputting 
   the date.
 * Guido
 * ps. I initially thought it was a Core issue, so have already created a ticket
   at [Make Core](https://core.trac.wordpress.org/ticket/48733), but apparently 
   I’m doing it wrong, so ticket is closed.

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

 *  Thread Starter [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/problems-with-timezone-when-using-new-function-wp_date/#post-12154459)
 * I might have fixed it…
 * To remove the additional timezone from site settings I have added a third parameter:
 *     ```
       $zone = new DateTimeZone('UTC');
       wp_date( $dateformat, esc_attr( $date ), $zone )
       ```
   
 * Guess this is the proper way to fix it?
 * Guido
 *  [autotutorial](https://wordpress.org/support/users/autotutorial/)
 * (@autotutorial)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/problems-with-timezone-when-using-new-function-wp_date/#post-12155158)
 * the time function of php returns a timestamp independent of the offeset.
    date_format
   uses the offset of the php script you can solve globally From php 5.1 [https://www.php.net/manual/en/function.date-default-timezone-set.php](https://www.php.net/manual/en/function.date-default-timezone-set.php)
   intstead of setting for data_format from PHP 5.2.1 [https://www.php.net/manual/en/datetime.format.php](https://www.php.net/manual/en/datetime.format.php)
   PHP 5.2.0: For UTC if is timestamp: [https://www.php.net/manual/en/datetime.settimezone.php](https://www.php.net/manual/en/datetime.settimezone.php)
   For all eccept UTC if is timestamp DateTimeZone: [https://www.php.net/manual/en/datetime.construct.php](https://www.php.net/manual/en/datetime.construct.php)
   Example: `$date = new DateTime($time,new DateTimeZone("UTC"));` $time not timestamp.
   if globally imposed, functions like strtotime have the expected results (your
   scripts or other scripts executed after you).
 * > [Date/Time component improvements in WordPress 5.3](https://make.wordpress.org/core/2019/09/23/date-time-improvements-wp-5-3/)
 * 
    the real question is WordPress set always as UTC (globally) in the core? I 
   can’t answer because the documentation is missing.
 *  [autotutorial](https://wordpress.org/support/users/autotutorial/)
 * (@autotutorial)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/problems-with-timezone-when-using-new-function-wp_date/#post-12155563)
 * [@guido07111975](https://wordpress.org/support/users/guido07111975/) sorry I 
   had forgotten, that you are using wp_date correctly.
    Edit is not recommended
   to set globally rather use DateTimeZone.
 *  Thread Starter [Guido](https://wordpress.org/support/users/guido07111975/)
 * (@guido07111975)
 * [6 years, 6 months ago](https://wordpress.org/support/topic/problems-with-timezone-when-using-new-function-wp_date/#post-12157120)
 * Hi,
 * Thanks for your response. I did update my plugin and it seems to be solved now
   🙂
 * Guido

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

The topic ‘Problems with timezone when using new function wp_date()’ is closed to
new replies.

## Tags

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

 * In: [Developing with WordPress](https://wordpress.org/support/forum/wp-advanced/)
 * 4 replies
 * 2 participants
 * Last reply from: [Guido](https://wordpress.org/support/users/guido07111975/)
 * Last activity: [6 years, 6 months ago](https://wordpress.org/support/topic/problems-with-timezone-when-using-new-function-wp_date/#post-12157120)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
