Support

Account

Home Forums General Issues Compare date field with current time in query Reply To: Compare date field with current time in query

  • It is a date/time field Set to return/show in this format:

    2021-01-23 12:01:54 | Y-m-d H:i:s

    So my thinking goes, i need to first establish if an unpublished date have been set, and if it has compare it to the current time.

    This is where im at right now: still not working as intended:

       $unpublish      = get_field('unpublish');
        $current_time   = date( 'Y-m-d H:i:s' );
    
        if( ! empty($unpublish) ) {
            array_push( $metaQuery, array(
    
                'key'       => 'unpublish',
                'compare'   => '>',
                'value'     => $current_time,
                ),
            );
        }