I have a custom meta box with a datepicker. The datepicker outputs 2013-01-17 10:00 in my database for an event that is 01-17-2013 at 10pm PST.

$eventlist = new WP_Query(array(
    'post_type' => 'events',
    'posts_per_page' => 5,
    'order' => 'asc',
    'orderby' => 'meta_value',
    'meta_key' => 'datetime',
    'meta_query' => array(
            'key' => 'datetime', // Check the start date field
            'value' => date("Y-m-d H:i:s"),  
            'compare' => '>=', 
            'type' => 'DATETIME' 

The issue is, at 4pm PST the event disappears, leading me to believe somewhere it is thinking its UTC and making the post go bye bye. Where would i Find this issue and how can i solve it?


WordPress sets the php timezone to UTC for internal calculations. So at 4pm PST, date() will be producing a date that reads 10pm UTC. Hence the event is considered past.

There are two ways to resolve this.

  1. (The preferred method) Store dates in the database in UTC. Handle all date calculations in UTC, and convert to the desired timezone on output (frontend and back).

  2. Use date_i18n()for creating the date to query (as this will set the date according to your blog timezone).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.