Pretty Filter URL

Here is my current code:

function hm_base_date_query_vars($vars) {
    $vars[] = 'base_date';

    return $vars;
}
add_filter('query_vars', 'hm_base_date_query_vars');

function hm_base_date_rewrite_rule() {
    add_rewrite_rule(
        '^my-calendar/([^/]*)/?',
        'index.php?pagename=my-calendar&base_date=$matches[1]',
        'top'
    );
}
add_action('init', 'hm_base_date_rewrite_rule', 10, 0);

$base_date_test = get_query_var('base_date');

on the url example.com/my-calendar/foo my var $base_date_test returns null

Maybe someone can help me. Thanks.

// Edit: It works. I tried to call the var in functions.php but I had to call it in my custom php template -.-