How to dynamically set the date range from grafana to my mysql query


I am using the latest version of grafana and trying to apply the selected date range within grafana (from and to range) for the mysql query i have

Pls find the attached image, this works fine but the date time range is hardcoded. Is there a way to pass the from and to date time range to my query command as follows ?

SELECT * from pd_alert where service_cat1='Fraud' AND created_at BETWEEN timestamp '2022-11-06 00:00:00' AND timestamp '2023-01-06 00:00:00'

Note: The format of created_at in my athena table is a timestamp of this format 2022-11-06 00:00:00

Here are some things i tried

FROM your_table
WHERE datetime_column BETWEEN TO_DATE('$__from') AND TO_DATE('$__to');
FROM your_table
WHERE datetime_column BETWEEN FROM_ISO8601_TIMESTAMP('$__from') AND FROM_ISO8601_TIMESTAMP('$__to');


Firstly you have posted two near-identical questions, I suggest you delete the other one.

I have not used timestamps (but timestamp and datetime are not all that different in MySQL) so normally I would just do:

FROM your_table
WHERE $__timeFilter(datetime_column)

And Grafana would handle the conversion, so the resulting SQL passed to the database might be something like this in my case:

datetime_column BETWEEN FROM_UNIXTIME(1641559127) AND FROM_UNIXTIME(1673095127)

Have you tried that on your timestamp column?


Thank you so much for the suggestion. I was able to get it working with the timeFilter