I'm trying to query some posts between 2 dates, look like it's not working because my posts are not int YYYYMMDD format but in european format DD.MM.YYYY
$args = array(
'orderby' => 'meta_value',
'meta_key' => 'usp-custom-rdvp_date_event_start',
"order" => "ASC",
'meta_query' => array(
array(
'key' => 'usp-custom-rdvp_date_event_start',
'value' => array( $fromDate, $toDate ),
'type' => 'DATE',
'compare' => 'BETWEEN',
),
),
);
Did you have a hack to query between 2 European date?
PS. I can't change the date format
You can easily change the date format with some array manipulation:
$mydate = 'DD.MM.YYYY';
echo implode( '', array_reverse( explode('.', $mydate) ) ); # Output: YYYYMMDD
You may also find a better way using the DateTime class.
$date_str = '02.04.2016';
$myDateTime = DateTime::createFromFormat( 'd.m.Y', $date_str );
echo $myDateTime->format( 'Ymd' ); # Output: 20160402