Hello thanks for your repply, if i change my date times setting become UTC, store dates become UTC too, am i right? i already test it like this
i used CURRENT_TIMESTAMP query to store dates, and my query in grafana is like this
SELECT
$__timeEpoch(time),
valueOne as value,
measurement as metric
FROM
metric_values
WHERE
$__timeFilter(time)
ORDER BY
time ASC
Regards
Hello, i change current_timestamp with utcgetdates, and its work well. but i want to ask some question. is grafana mssql only work with utc international ? because if i use timezone with local browser or default, the value appear in grafana is more faster 7 hours. Thanks
Regards
The timestamps in the database should be in UTC. However it is not necessarily obvious how to get timestamps into the db in UTC. It may be that when you pass a timestamp to MSSQL it assumes it is in local time, so actually the way to get the timestamp in UTC is to pass it in local time. You will have to ask an MSSQL expert on how to do that.
Once you achieve that then Grafana will convert that to local time (except that for some reason you seem to insist on getting it show UTC, is that really what you want?
So, I suggest you set your machine back to local time, set the graph to show local time, then experiment with ways of setting the timestamp on records you insert till it shows the correct local time.
Hello, the current_timestamp does not stored utc time, it only show your pc / local time. I already test with getutcdate, its working on utc. but my timezone is utc+07:00, and every single value stored to database, it will appear in grafana faster 7 hour, example in database stored 14:27, but in grafana will appear at 21:27, and i really have no idea about this issue.
Follow my advice, first set everything back to local time. Is everything ok then except that the timestamps on the data are 7 hours out? If so then you just need to work out what incantation to use the get the timestamps into the database.
As @clanlaw suggest you should use GETUTCDATE()
when inserting your data. For the existing data it should be a rather simple UPDATE statement
to update all existing stored dates and convert them to UTC time.
I already follow, set everything. even the timezone i used local browser. Still, the value are stored faster 7 hour. and i already try to change time values with this querys:
SYSDATETIME()
SYSDATETIMEOFFSET()
CURRENT_TIMESTAMP
GETDATE()
Still nothing change, the value only stored in the right time when using UTC time zone
Hi, i already tested it before. yes, the issue is solved. but this is means i cannot use local time, so my conclusion is:
- Use UTC time zone, but only use today on time range(the values appear the right time, same as time which stored in database).
- Use UTC Time zone, and change current_timestamp with getutcdates(), this also working, but only for utc+12:00 time, this is also ok but i still wan’t to research how to Use local browser time zone, but the data which stored to database and grafana are the same time, not delayed for 7 hours. thanks
You cannot store dates in local time in database yes, but you can select local browser time as timezone in Grafana UI.
thanks, its worked, thanks for your support
I think that is what I said to do, a number of posts ago.
1 Like