# Formatting sqlite timestamp recognizable time

**URL:** <https://community.grafana.com/t/formatting-sqlite-timestamp-recognizable-time/53475>\
**Category:** Time Series Panel\
**Created:** [September 18, 2021, 4:06am UTC](https://community.grafana.com/t/formatting-sqlite-timestamp-recognizable-time/53475 "2021-09-18T04:06:16Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![lucywinters](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lucywinters](https://community.grafana.com/u/lucywinters)\
**Post date:** [September 18, 2021, 4:06am UTC](https://community.grafana.com/t/formatting-sqlite-timestamp-recognizable-time/53475/1 "2021-09-18T04:06:17Z")

</div>

Hi There,  
I’m very new to grafana and am struggling to get my graph to show anything. I can get the table to show the values. So data source connection seems ok. I believe the issue with graphing is the Timestamp column (or its formatting)

I’m pulling data from my solar panels stored in a sqlite database [using this script](https://github.com/minkley/fronius) and have installed the SQLite datasource plugin and can see the data from my sqlite db.

**From sqllite**  
sample of the data (only the two colums I’m after)  
sqlite\> select Timestamp,P\_PV from site LIMIT 2;  
2021-09-18T11:47:02+10:00|1384  
2021-09-18T11:47:02+10:00|1384

**Grafana Queries**  
After reading these articles [this](https://grafana.com/grafana/plugins/frser-sqlite-datasource/) I tried a number of grafana queries where I convert the Timestamp column to datetime format but no luck. In all of these the column (in table view looks to be time format)

```auto
WITH CONVERTED AS
(SELECT P_PV, STRFTIME('%Y-%m-%dT%H:%M:%SZ', Timestamp) AS Time FROM site)

SELECT Time, P_PV FROM CONVERTED ORDER BY Time ASC

```

I’m almost certain that this be because of the way that my Timestamp column is being read by grafana as not being a timesource.  
In table view the times are showing as follows format:  
2021-09-18 11:47:02  
2021-09-18 11:47:02  
2021-09-18 11:47:07

I’ve also tried by just having unixtimestamp eg (1631937866) as the time field and still cannot get the graph to show.  
Hope this makes sense to people, and I hope it’s something simple that people can help with.

Many thanks  
Lucy

---

<div class="post-metadata">

**Author:** ![sburke781](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/sburke781/32/14144_2.png) [@sburke781](https://community.grafana.com/u/sburke781)\
**Post date:** [September 19, 2021, 1:41am UTC](https://community.grafana.com/t/formatting-sqlite-timestamp-recognizable-time/53475/2 "2021-09-19T01:41:55Z")

</div>

Hi Lucy,

Weirdly I was just talking with someone else about formatting of dates in his charts and he was able to achieve this by adjusting the Grafana server-wide settings, outlined in this blog post:

> **[Grafana v7.2 released with custom date formats, new transforms and overrides](https://grafana.com/blog/2020/09/23/grafana-v7.2-released-with-custom-date-formats-new-transforms-and-overrides/)**
>
> The Grafana 7.2 release includes enhancements for several data sources and panels. Find out all the details here.

Hopefully this will help you get the format you need.

If you need to do this on a specific dashboard / query, then I’m not sure on how best to achieve this.

Good luck,  
Simon

---

<div class="post-metadata">

**Author:** ![lucywinters](https://avatars.discourse-cdn.com/v4/letter/l/73ab20/32.png) [@lucywinters](https://community.grafana.com/u/lucywinters)\
**Post date:** [September 19, 2021, 5:41am UTC](https://community.grafana.com/t/formatting-sqlite-timestamp-recognizable-time/53475/3 "2021-09-19T05:41:42Z")

</div>

Hi Simon,

Thanks for that link - it looks interesting, I now think my issue is more related to the actual query in grafana.

I’ve tweaked the query to return the date in a RFC3339 format (eg: “2006-01-02T15:04:05Z07:00”) which I believe is the required format for the sqlite plugin.

My Query now is:

```auto
WITH converted AS (
SELECT E_Day, REPLACE(Timestamp, '+','Z') AS datetime FROM site WHERE Timestamp
)
SELECT datetime, E_Day FROM converted ORDER BY datetime ASC

```

Now the issue I have is nothing is shown on the graph - with an error: “Invalid Date:”

Anyone have any pointers or suggestions?

---

<div class="post-metadata">

**Author:** ![sburke781](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/sburke781/32/14144_2.png) [@sburke781](https://community.grafana.com/u/sburke781)\
**Post date:** [September 20, 2021, 11:18am UTC](https://community.grafana.com/t/formatting-sqlite-timestamp-recognizable-time/53475/4 "2021-09-20T11:18:07Z")

</div>

Hi Lucy,

I am wondering whether your query text may have got cut off…? The WHERE clause does not seem to be complete for the definition for “converted”. Also, I am wondering whether the use of the keyword / datatype “datetime” may be problematic? The only other thing I can suggest is placing a CAST or CONVERT around the REPLACE(Timestamp, ‘+’,‘Z’), as it would currently be returning a string, I would expect, and if Grafana is expecting a date, that could be throwing it off…

---

<div class="post-metadata">

**Author:** ![supportd710](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@supportd710](https://community.grafana.com/u/supportd710)\
**Post date:** [October 29, 2021, 8:04am UTC](https://community.grafana.com/t/formatting-sqlite-timestamp-recognizable-time/53475/5 "2021-10-29T08:04:04Z")

</div>

Hi everyone! I have the same struggle right now. I have just simple test table with timestamp and value. So, my timestamp is in epoch unix format, as you can see:  
 ![image](https://us1.discourse-cdn.com/grafana/original/3X/8/9/893dfdc30c440b255fc868cafd6a416daa076170.png)  
I use same SQLite plugin, and data source connection is ok, i test it on two different machines with windows and linux.  
Plugin should allow me convert timestamp automatically, as it is in unix format and i can see that this is true, because when i switch to the table view, i get correct results:

 ![image](https://us1.discourse-cdn.com/grafana/original/3X/c/a/ca7c7b264228f42606232d371426753b9526fe09.png)  
But I can’t get “Time series” graph, there is no any data points, and i don’t understand what is the issue, everything seems correct to me.  
I’ve just started working with Grafana, so any help is appreciated.

Many Thanks, Daniil
