Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#36309 new enhancement

Timezone issue in WP_Date_Query->build_mysql_datetime

Reported by: fadlee's profile fad.lee Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.4.2
Component: Query Keywords:
Focuses: Cc:


Currently build_mysql_datetime function in WP_Date_Query using gmdate to generate SQL datetime.

if ( ! is_array( $datetime ) ) {
        // @todo Timezone issues here possibly
        return gmdate( 'Y-m-d H:i:s', strtotime( $datetime, $now ) );

That leads to unexpected result in my use case.

My timezone is GMT -7.

When I want to get posts before the current post (e.g. post_date 2015-12-30 14:00:02), the query get posts before 2015-12-30 07:00:02.

That not what I want.

I'm trying to use GMT with get_post_time function, but the query get posts before 00:00:02. Farther from what I want.

I think this function not need to change date timezone with gmdate. Just use datetime as is with date function.

Change History (0)

Note: See TracTickets for help on using tickets.