How to get posts by date range in WordPress?

On my WordPress website, I have a custom post type called booking. Basically, I want to build a filter system where user can filter their posts (booking) by date range. I am using jQuery daterangepicker to select the date range now how can I implement the backend code in the WordPress theme?

I can think of WordPress hook pre_get_posts and set the day there but the problem is it will bring bookings from every month and every year. There is another problem I can’t set the date range there. Like how can I get posts published between two specific dates?

function get_custom_booking( $query ) {
    if ( $query->is_main_query() && is_post_type_archive( 'booking' ) ) {
        // Set the date range logic

    }
}
add_action( 'pre_get_posts', 'get_custom_booking' );

I am kinda stuck here.

You can use date_query.

function get_custom_booking( $query ) {
    if ( $query->is_main_query() && is_post_type_archive( 'booking' ) ) {
        $query->set('date_query', array(
            array(
                'after'     => 'December 1st, 2021',
                'before'    => 'January 31st, 2022',
                'inclusive' => true
            ),
        ));
    }
}
add_action('pre_get_posts', 'get_custom_booking');

You can also use wp_query to get the posts in the date range.

$args = array(
    'date_query' => array(
        array(
            'after'     => 'December 1st, 2021',
            'before'    => 'January 31st, 2022',
            'inclusive' => true,
        ),
    ),
);
$query = new WP_Query( $args );