• Hello

    I come up with a problem in WordPress, wp_query. It’s turns out that making a “compare” between 2 date in a meta_query work well with YYYYMMDD format, what is standard wordpress, but don’t work with DD.MM.YYYY format.

    If I query between the same month for example 10.10.2016 and 12.10.2016, I get in return all event with day “10, 11, 12” even if not in the same month or year!

    If I query between different month for example 10.10.2016 and 12.01.2017, I get nothing in return.

    `$args = array(
    ‘orderby’ => ‘meta_value’,
    ‘meta_key’ => ‘usp-custom-rdvp_date_event_start’,
    “order” => “ASC”,
    ‘meta_query’ => array(
    array(
    ‘relation’ => ‘AND’,
    array(
    ‘key’ => ‘usp-custom-rdvp_date_event_start’,
    ‘value’ => array( $fromDate, $toDate ),
    ‘compare’ => ‘BETWEEN’,
    ‘type’ => ‘DATE’,
    ),
    [other code not useful here…]
    ),
    ),
    );

    Pay attention: I got plenty of people telling me you can change your date format with php DateTime::format() or mktime. This is not the problem the DB field “usp-custom-rdvp_date_event_start” and var $fromDate $toDate are in the same format what is DD.MM.YYYY. It just turn out that WP_Query isn’t interpreting DD.MM.YYYY as a date. Ok I can change my php var, but I can’t change my value in db…

    Thanks for your help

    • This topic was modified 8 years, 2 months ago by Iteration.
  • The topic ‘[wp_query] meta_query between 2 dates when format is not YYYYMMDD’ is closed to new replies.