# Time Sync Issue

**URL:** <https://community.grafana.com/t/time-sync-issue/32425>\
**Category:** Configuration\
**Created:** [June 20, 2020, 3:27pm UTC](https://community.grafana.com/t/time-sync-issue/32425 "2020-06-20T15:27:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![capnjackoff](https://avatars.discourse-cdn.com/v4/letter/c/7ab992/32.png) [@capnjackoff](https://community.grafana.com/u/capnjackoff)\
**Post date:** [June 20, 2020, 3:27pm UTC](https://community.grafana.com/t/time-sync-issue/32425/1 "2020-06-20T15:27:04Z")

</div>

Hello, it’s amazing I got anything to display at all in Grafana. I am a total query n00b.  
I have a php script logging data and correct local timestamps in a MySQL database.

 ![gCap1](https://us1.discourse-cdn.com/grafana/original/2X/2/24ae0ba7b0fcd2dc4e0333848591ea68f00baac3.jpeg)

I have a simple query in Grafana:

> SELECT  
> Timestamp AS “time”,  
> Watts  
> FROM SolarEberlein  
> Order by Timestamp

For some reason, the entries only show up at the correct times if I select UTC as my timezone. **Why?**  
It’s almost as if Grafana assumes my timestamps are Unix.

 ![gcap3](https://us1.discourse-cdn.com/grafana/original/2X/3/35ed32798dc00b1122431addaca2400c2b8dd669.jpeg)

---

<div class="post-metadata">

**Author:** ![pooh](https://avatars.discourse-cdn.com/v4/letter/p/f05b48/32.png) [@pooh](https://community.grafana.com/u/pooh)\
**Post date:** [June 20, 2020, 3:45pm UTC](https://community.grafana.com/t/time-sync-issue/32425/2 "2020-06-20T15:45:43Z")

</div>

> Hello, it’s amazing I got anything to display at all in Grafana. I am a  
> total query n00b. I have a php script logging data and correct local  
> timestamps in a MySQL database.

Oh dear - what do you mean by “local timestamps”?

If they’re not in UTC, you’ll have problems…

> I have a simple query in Grafana:
> 
> > SELECT Timestamp AS “time”, Watts FROM SolarEberlein Order by Timestamp
> 
> For some reason, the entries only show up at the correct times if I select  
> UTC as my timezone. **Why?**

Because Grafana requires timestamps stored in the database to be in UTC.

> It’s almost as if Grafana assumes my timestamps are Unix.

Yes.

Store your timestamps in UTC and you won’t have these problems (and you won’t  
have even more problems when the clocks change, either).

Regards,

Antony.

---

<div class="post-metadata">

**Author:** ![codlord](https://avatars.discourse-cdn.com/v4/letter/c/b5ac83/32.png) [@codlord](https://community.grafana.com/u/codlord)\
**Post date:** [June 20, 2020, 4:31pm UTC](https://community.grafana.com/t/time-sync-issue/32425/3 "2020-06-20T16:31:27Z")

</div>

You may be able to work around this with MySQL by using the MySQL function UNIX\_TIMESTAMP:  
`select UNIX_TIMESTAMP(datetime)*1000 as 'Date/Time'`

Another alternative is to use the MySQL function CONVERT\_TZ:  
`select CONVERT_TZ(datetime, 'SYSTEM', 'UTC') as 'Date/Time'`

I use it successfully with DATETIME types anyway converting from London timezone to UTC.

Just note that before you can use CONVERT\_TZ you do have to populate the timezone tables, for me in the UK I did this but what you need may be different:

`mysql_tzinfo_to_sql /usr/share/zoneinfo/GB "Europe/London" |sudo mysql -u root -p mysql`  
`mysql_tzinfo_to_sql /usr/share/zoneinfo/UTC "UTC" |sudo mysql -u root -p mysql`

And if you have any timezone changes in future in your region like daylight savings time changes then things could be wrong until you update the timezone tables again.
