I have a problem with the use of $__timeFilter(), in fact it doesn’t give the right date at all to filter the data no matter what time zone you choose. There’s always a 2h offset (I’m in UTC+2).
Here are 3 identical requests (except one where I add the $__timefilter()) and the results are not identical:
The correct result is obviously on MSSQL, but I don’t understand why the $__timeFilter() has such an effect on the result. It’s impossible to get the right result, and even worse when we just look at the date by applying UTC+2 in time zones Grafana makes us think we’re smme at the right date when in fact it’s only modifying the date imported from the database but not actually fetching the data at that date.
Thank you for your answer, it’s really not practical …, ed plus I couldn’t find a way to apply this conversion to the $__timeFilter() macro, I had to use $__timeFrom() AND $__timeTo()… $__timeFilter() is only useful if you’re in UTC, otherwise you might as well do something else…
By selecting my time zone in the time picker, and replacing $__timeFilter(date) with Date AT TIME ZONE ‘Central European Standard Time’ BETWEEN $__timeFrom() AND $__timeTo() it works correctly. But it’s a pity you can’t use $__timeFilter easily if you’re not in UTC+0.
you can just use cte to convert the data before applying that function
;with utc_converted
as
(
select id,
CONVERT(DATETIME,
starttime AT TIME ZONE 'Central European Standard Time'
AT TIME ZONE 'UTC') as starttime
from xys
where equipment = 'sdsds'
)
select top 1 id, starttime
from utc_converted
where$__timeFilter(starttime )
order by date desc