Get orders by date and status woocommerce



PHP Snippet 1:

$initial_date = yyyy-mm-dd;
$final_date = yyyy-mm-dd;
$orders = wc_get_orders(array(
    'limit'=>-1,
    'type'=> 'shop_order',
    'status'=> array( 'wc-completed','wc-refunded' ),
    'date_created'=> $initial_date .'...'. $final_date 
    )
);

PHP Snippet 2:

global $wpdb;

$date_from = '2015-11-20';
$date_to = '2015-12-20';
$post_status = implode("','", array('wc-processing', 'wc-completed') );

$result = $wpdb->get_results( "SELECT * FROM $wpdb->posts 
            WHERE post_type = 'shop_order'
            AND post_status IN ('{$post_status}')
            AND post_date BETWEEN '{$date_from}  00:00:00' AND '{$date_to} 23:59:59'
        ");

echo "<pre>";
print_r($result);

PHP Snippet 3:

$timestamp_start = '2022-04-07 20:00:00.000'; // example
$timestamp_end   = '2022-04-21 20:00:01.000'; // example
'date_created' => strtotime($timestamp_start ) .'...'. strtotime($timestamp_end)