# Tag History SQL Query Result Timestamp

**URL:** <https://forum.inductiveautomation.com/t/tag-history-sql-query-result-timestamp/73609>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [May 11, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/tag-history-sql-query-result-timestamp/73609 "2023-05-11T18:42:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aman\_Pawar](https://avatars.discourse-cdn.com/v4/letter/a/7ba0ec/32.png) [@Aman\_Pawar](https://forum.inductiveautomation.com/u/Aman_Pawar)\
**Post date:** [May 11, 2023, 6:42pm UTC](https://forum.inductiveautomation.com/t/tag-history-sql-query-result-timestamp/73609/1 "2023-05-11T18:42:49Z")

</div>

I wanted to use SQL query to fetch tag history data of particular tag so I've used following query:

SELECT tagid, intvalue, t\_stamp, DATEADD(s,t\_stamp/1000,'1970-01-01 00:00:00') as Time\_Stamp FROM sqlt\_data\_1\_2023\_04 where tagid = 4460  
and DATEADD(s,t\_stamp/1000,'1970-01-01 00:00:00') \>= '2023-04-28 12:00:00.000'  
and DATEADD(s,t\_stamp/1000,'1970-01-01 00:00:00') \< '2023-04-29 00:00:00.000'  
order by [t\_stamp]

Now my question is the timestamp I get from above conversion in the result is with respect to UTC time zone or gateway time zone?

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [May 11, 2023, 7:06pm UTC](https://forum.inductiveautomation.com/t/tag-history-sql-query-result-timestamp/73609/2 "2023-05-11T19:06:37Z")

</div>

What makes you not want to use a _Tag History_ binding or the [system.tag.queryTagHistory](https://docs.inductiveautomation.com/display/DOC81/system.tag.queryTagHistory) function?

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [May 11, 2023, 7:10pm UTC](https://forum.inductiveautomation.com/t/tag-history-sql-query-result-timestamp/73609/3 "2023-05-11T19:10:35Z")

</div>

According to the [docs](https://docs.inductiveautomation.com/display/DOC81/Ignition+Database+Table+Reference), the t\_stamp is a Unix timestamp, which would mean it's UTC.

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 11, 2023, 7:23pm UTC](https://forum.inductiveautomation.com/t/tag-history-sql-query-result-timestamp/73609/4 "2023-05-11T19:23:32Z")

</div>

> [@Aman\_Pawar](#):
>
> SELECT tagid, intvalue, t\_stamp, DATEADD(s,t\_stamp/1000,'1970-01-01 00:00:00') as Time\_Stamp FROM sqlt\_data\_1\_2023\_04 where tagid = 4460  
> and DATEADD(s,t\_stamp/1000,'1970-01-01 00:00:00') \>= '2023-04-28 12:00:00.000'  
> and DATEADD(s,t\_stamp/1000,'1970-01-01 00:00:00') \< '2023-04-29 00:00:00.000'  
> order by [t\_stamp]

This is going to be terribly inefficient. Instead of converting each row's timestamp in the WHERE clause, convert the constants to UTC milliseconds. The WHERE clause will run much, much faster.
