Working with dates in SQLite and Grafana
Posted: | Tags: grafana sqlite tilSQLite can be used as a data source for Grafana using a community plugin maintained by fr-ser. Out of the box the plugin has support for time formatted columns, which work on visuals like time series, and time range macros, which use the dashboards datetime picker. This post has a few of my notes.
Unix epoch numbers (e.g. 1773149763) and RFC3339 strings (e.g. 2026-03-10T15:36:03+01:00) work natively for time formatted columns. The documentation has an example of how to fix malformed RFC3339 strings to work with the plugin. You may use the concatenate operator (||), replace() and other functions to fix your timestamps.
The following goes from a timestamp value of 2026-03-10 15:36:03 to 2026-03-10T15:36:03Z.
SELECT
REPLACE(timestamp, ' ', 'T') || 'Z' AS datetime,
measurement
FROM timeseries
ORDER BY datetime ASC
As for time range filtering, the plugin supports ${__from:date} and ${__to:date} which allows you to dynamically display results based on the time range set on the dashboard by using the WHERE clause in your queries.
WHERE timestamp BETWEEN '${__from:date}' AND '${__to:date}'
Building on the first example, the complete query will look like this:
SELECT
REPLACE(timestamp, ' ', 'T') || 'Z' AS datetime,
measurement
FROM timeseries
WHERE REPLACE(timestamp, ' ', 'T') || 'Z' BETWEEN '${__from:date}' AND '${__to:date}'
ORDER BY datetime ASC
If you’re familiar using time filters in Grafana with other data sources you may have encountered the $__timeFilter(timestamp) macro which shortens the WHERE clause. This is not currently supported by the plugin.