WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#38642 closed defect (bug) (invalid)

current_time('mysql') and current_time('Y-m-d H:i:s') are returning different values

Reported by: yeetien Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.6.1
Component: Date/Time Keywords:
Focuses: Cc:

Description

current_time('mysql') is returning the local time correctly but current_time('Y-m-d H:i:s') is not.

Maybe default case in current_time() should be using gmdate() instead of date()?

Change History (3)

#1 @dd32
4 years ago

Hi @yeetien and welcome back to Trac.

WordPress operates with it's internal default timezone set to UTC, so under normal situations date(), gmdate() and time() should all be returning the same timezone data - UTC (See #10940)

In your case, it sounds like the default date timezone is set to something other than UTC, most likely because a plugin is incorrectly calling date_default_timezone_set(), which would result in the scenario you're reporting.

Now that being said, I see no reason why this function is using both gmdate() and date(), but even fixing this you're likely to other dates being off elsewhere in WordPress where date() is used in the expectation that it's been set to UTC.

What timezone do you have WordPress set to? What about the PHP default timezone? Do you still experience it without plugins and using a default theme?

#2 @yeetien
4 years ago

  • Resolution set to invalid
  • Status changed from new to closed

Hi @dd32! Thanks for the prompt reply!

WordPress timezone is Asia/Singapore
PHP timezone is UTC

The problem actually happens on staging sever. I tried setting my local machine to UTC (default was Asia/Singapore), and current_time('mysql') and current_time('Y-m-d H:i:s') are returning the same value.

Think you right that the discrepancy is caused by some plugin. Or maybe it's some other server settings.

Sorry that I reported a false positive. I'll update here if I find out more info.

#3 @netweb
4 years ago

  • Milestone Awaiting Review deleted
Note: See TracTickets for help on using tickets.