I thought I did this exact same thing beforehand and it wasn’t working until I realized I forgot to add a colon : before the equal = sign in assigning the variable. That was why it wasn’t working, thanks!
Add to that the error in the console was saying executing "page" at <.>: undefined variable: $date so I thought my variable was not being made available in the lower context where I needed to use it.