Searching for a specific month in a metadata saved as Timestamp (Wp_Query)

I found the solution after a long search. Thank you very much to Misha Rudrastyh who gave me a great idea in my solution. You can check out the great guide that he prepared for meta_query.

Here is the solution:

First, get the first and last day of the month as described here (thanks for Francois Deschenes).

$month="2020-05";

// First day of the month.
$first_day = strtotime( date('Y-m-01', strtotime($month)) );
// Last day of the month.
$last_day = strtotime( date('Y-m-t', strtotime($month)) );

I use it as a timestamp because I keep the expected payment dates in this way. For more details, I suggest you check Misha’s guide.

Once you have the dates correctly fetched, all you have to do is prepare the wp_query arguments.

$args = array(
    'post_type'       => array( 'payments' ),
    'posts_per_page'  => -1,
    'post_status'     => array( 'publish' ),
    'meta_query '     => array(
        'key' => '_eo_payment_expected_date',
        'value' => array( $first_day, $last_day ),
        'type' => 'numeric',
        'compare' => 'BETWEEN'
    )
);

That is all.