Query with time variable

Hello, I don’t know how I can make this part of the query variable, depending on the set period, can someone please support me?

WHERE date(UnixTime, 'unixepoch') between date('now','-30 day') and date('now')  GROUP by date(UnixTime, 'unixepoch')

@frank86 just checking:

have you explored using Grafana’s global variables that relate to time, such as $__interval or $__timeFilter?