SQL use date var if selected or use now()

I know this may seem a little silly but my team has a use case for this. They want to know if it is possible to have a native query go off the timestamp of now() IF the date variable does not have a value. And IF the date variable has a value then use the date variable. So far we have tried the following and it is not working like we would have hoped.

where DATE_FORMAT(date, "%M %d %Y") = DATE_FORMAT(now(), "%M %d %Y")
[[and {{date}}]]

where case
when {{date}} then DATE_FORMAT(date, "%M %d %Y") = DATE_FORMAT(now(), "%M %d %Y") else {{date}}
end

The reason my team wants this is due to our dashboards going off of utc time instead of our reporting time of mountain, and do not want to make any changes to servers or db's in order to properly fix the issue

Hi @BrettJohnson2
Yes, use Optional Clauses with Complex Default Value:
https://www.metabase.com/docs/latest/users-guide/13-sql-parameters.html#setting-complex-default-values-in-the-query
Also worth a read too: Need help CURRENT_DATE() giving error

1 Like

That was it, thank you very much for you help!