# Help with queryTagHistory and intervalMinutes

**URL:** <https://forum.inductiveautomation.com/t/help-with-querytaghistory-and-intervalminutes/16785>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [January 29, 2018, 6:54pm UTC](https://forum.inductiveautomation.com/t/help-with-querytaghistory-and-intervalminutes/16785 "2018-01-29T18:54:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [January 29, 2018, 6:54pm UTC](https://forum.inductiveautomation.com/t/help-with-querytaghistory-and-intervalminutes/16785/1 "2018-01-29T18:54:22Z")

</div>

Hello,  
I need help on retrieving historical data for every hour withing an 8 hour period. It seems I don’t understand the meaning of “intervalMinutes”.  
Bellow is a quick script and its results, can anyone help me out on retrieving data for only one hour for each hour?

endTime = system.date.now()  
startTime = system.date.addMinutes(endTime, -480)  
dataSet = system.tag.queryTagHistory(paths=[‘Total Cup Produced’], startDate=startTime, endDate=endTime, returnSize=-1, aggregationMode=“MinMax”, returnFormat=‘Wide’,intervalMinutes=60)  
for row in range(dataSet.rowCount):  
tamp = dataSet.getValueAt(row,0)  
total = dataSet.getValueAt(row,1)  
print tamp,total

Mon Jan 29 07:34:34 CST 2018 0  
Mon Jan 29 07:34:44 CST 2018 12  
Mon Jan 29 07:35:04 CST 2018 42  
Mon Jan 29 07:35:14 CST 2018 54  
Mon Jan 29 07:35:44 CST 2018 54  
Mon Jan 29 07:36:04 CST 2018 72  
Mon Jan 29 07:36:34 CST 2018 72  
Mon Jan 29 07:36:44 CST 2018 78  
Mon Jan 29 07:37:04 CST 2018 108  
Mon Jan 29 07:37:14 CST 2018 117  
Mon Jan 29 07:38:04 CST 2018 117  
Mon Jan 29 07:38:14 CST 2018 126  
Mon Jan 29 07:38:34 CST 2018 156  
Mon Jan 29 07:38:44 CST 2018 168  
Mon Jan 29 07:39:34 CST 2018 168  
Mon Jan 29 07:41:04 CST 2018 303  
Mon Jan 29 07:43:04 CST 2018 483  
Mon Jan 29 07:43:14 CST 2018 492  
Mon Jan 29 07:43:24 CST 2018 492  
Mon Jan 29 07:45:04 CST 2018 642  
Mon Jan 29 07:45:14 CST 2018 648  
Mon Jan 29 07:45:24 CST 2018 657  
Mon Jan 29 07:45:34 CST 2018 672  
Mon Jan 29 07:45:44 CST 2018 681  
Mon Jan 29 07:51:34 CST 2018 681  
Mon Jan 29 07:51:44 CST 2018 687  
Mon Jan 29 07:53:04 CST 2018 807  
Mon Jan 29 07:53:14 CST 2018 819  
Mon Jan 29 07:53:24 CST 2018 837  
Mon Jan 29 07:58:54 CST 2018 1332  
Mon Jan 29 07:59:05 CST 2018 1347  
Mon Jan 29 07:59:15 CST 2018 1359  
Mon Jan 29 08:00:15 CST 2018 1449  
Mon Jan 29 08:00:25 CST 2018 1467  
Mon Jan 29 08:03:05 CST 2018 1707  
Mon Jan 29 08:03:15 CST 2018 1719  
Mon Jan 29 08:03:35 CST 2018 1749  
Mon Jan 29 08:03:45 CST 2018 1767  
Mon Jan 29 08:05:05 CST 2018 1887  
Mon Jan 29 08:05:15 CST 2018 1899  
Mon Jan 29 08:05:35 CST 2018 1929  
Mon Jan 29 08:05:45 CST 2018 1947  
Mon Jan 29 08:11:45 CST 2018 2487  
Mon Jan 29 08:11:55 CST 2018 2496  
Mon Jan 29 08:19:25 CST 2018 2496  
Mon Jan 29 08:19:35 CST 2018 2499  
Mon Jan 29 08:21:25 CST 2018 2664  
Mon Jan 29 08:21:35 CST 2018 2676  
Mon Jan 29 08:22:45 CST 2018 2781  
Mon Jan 29 08:22:55 CST 2018 2799  
Mon Jan 29 08:23:05 CST 2018 2814  
Mon Jan 29 08:23:15 CST 2018 2826  
Mon Jan 29 08:24:25 CST 2018 2931  
Mon Jan 29 08:24:35 CST 2018 2949  
Mon Jan 29 08:27:05 CST 2018 3174  
Mon Jan 29 08:27:15 CST 2018 3186  
Mon Jan 29 08:27:35 CST 2018 3216  
Mon Jan 29 08:27:45 CST 2018 3234  
Mon Jan 29 08:31:25 CST 2018 3564  
Mon Jan 29 08:31:35 CST 2018 3567  
Mon Jan 29 08:35:45 CST 2018 3567  
Mon Jan 29 08:36:45 CST 2018 3657  
Mon Jan 29 08:36:55 CST 2018 3675  
Mon Jan 29 08:37:45 CST 2018 3750  
Mon Jan 29 08:37:55 CST 2018 3753  
Mon Jan 29 08:38:25 CST 2018 3753  
Mon Jan 29 08:38:35 CST 2018 3756  
Mon Jan 29 08:38:55 CST 2018 3786  
Mon Jan 29 08:39:05 CST 2018 3804  
Mon Jan 29 08:39:15 CST 2018 3816  
Mon Jan 29 08:42:05 CST 2018 4071  
Mon Jan 29 08:42:15 CST 2018 4074  
Mon Jan 29 08:45:45 CST 2018 4074  
Mon Jan 29 08:45:55 CST 2018 4077  
Mon Jan 29 08:51:25 CST 2018 4572  
Mon Jan 29 08:51:35 CST 2018 4590  
Mon Jan 29 08:51:55 CST 2018 4620  
Mon Jan 29 08:52:05 CST 2018 4623  
Mon Jan 29 08:55:25 CST 2018 4623  
Mon Jan 29 08:55:35 CST 2018 4635  
Mon Jan 29 08:57:45 CST 2018 4830  
Mon Jan 29 08:58:05 CST 2018 4830  
Mon Jan 29 08:58:15 CST 2018 4836  
Mon Jan 29 08:58:35 CST 2018 4866  
Mon Jan 29 09:02:45 CST 2018 4866  
Mon Jan 29 09:02:55 CST 2018 4875  
Mon Jan 29 09:03:05 CST 2018 4893  
Mon Jan 29 09:03:15 CST 2018 4905  
Mon Jan 29 09:03:55 CST 2018 4965  
Mon Jan 29 09:04:05 CST 2018 4968  
Mon Jan 29 09:06:55 CST 2018 4968  
Mon Jan 29 09:07:05 CST 2018 4971  
Mon Jan 29 09:08:55 CST 2018 5136  
Mon Jan 29 09:09:15 CST 2018 5166  
Mon Jan 29 09:13:05 CST 2018 5511  
Mon Jan 29 09:13:15 CST 2018 5523  
Mon Jan 29 09:13:25 CST 2018 5541  
Mon Jan 29 09:16:05 CST 2018 5781  
Mon Jan 29 09:16:15 CST 2018 5790  
Mon Jan 29 09:20:05 CST 2018 5790  
Mon Jan 29 09:20:15 CST 2018 5802  
Mon Jan 29 09:21:05 CST 2018 5877  
Mon Jan 29 09:21:15 CST 2018 5883  
Mon Jan 29 09:21:25 CST 2018 5892  
Mon Jan 29 09:21:35 CST 2018 5907  
Mon Jan 29 09:21:45 CST 2018 5925  
Mon Jan 29 09:21:55 CST 2018 5937  
Mon Jan 29 09:22:35 CST 2018 5937

---

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [January 29, 2018, 8:09pm UTC](https://forum.inductiveautomation.com/t/help-with-querytaghistory-and-intervalminutes/16785/2 "2018-01-29T20:09:02Z")

</div>

found a way to do it by modifying the dataset although is not 100% what I wanted.  
Created two variables and formatted the time to include only the Hour and only print the first occurrence.

tamp1 = “”  
tamp2 = “”  
for row in range(dataSet.rowCount):  
tamp1 = system.db.dateFormat(dataSet.getValueAt(row,0),“MM-dd-yyyy HH”)  
total = dataSet.getValueAt(row,1)  
if tamp1 \<\> tamp2:  
print tamp1,total  
tamp2=tamp1

---

<div class="post-metadata">

**Author:** ![jmonter](https://avatars.discourse-cdn.com/v4/letter/j/858c86/32.png) [@jmonter](https://forum.inductiveautomation.com/u/jmonter)\
**Post date:** [February 9, 2018, 3:46am UTC](https://forum.inductiveautomation.com/t/help-with-querytaghistory-and-intervalminutes/16785/3 "2018-02-09T03:46:37Z")

</div>

The script above works fine in the Script Console producing the historic data but when executed on a Gateway Event Script there is no data provided.

Anyone know of any limitation with system.tag.queryTagHistory inside a gateway script?

---

<div class="post-metadata">

**Author:** ![tashby](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tashby/32/67562_2.png) [@tashby](https://forum.inductiveautomation.com/u/tashby)\
**Post date:** [January 31, 2020, 4:52am UTC](https://forum.inductiveautomation.com/t/help-with-querytaghistory-and-intervalminutes/16785/4 "2020-01-31T04:52:22Z")

</div>

I’m having this same issue. Using the system.tag.queryTagHistory in the designer will grab the data and I can write it to a tag database. However, if I put the exact same script in the gateway event script it returns a null value for the data value along with the correct time stamp. not sure what the deal is. version is 7.9.5. Any solution to this?

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [January 31, 2020, 3:57pm UTC](https://forum.inductiveautomation.com/t/help-with-querytaghistory-and-intervalminutes/16785/5 "2020-01-31T15:57:00Z")

</div>

Do you have the tag provider in the tagpath?

---

<div class="post-metadata">

**Author:** ![tashby](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tashby/32/67562_2.png) [@tashby](https://forum.inductiveautomation.com/u/tashby)\
**Post date:** [February 1, 2020, 1:24am UTC](https://forum.inductiveautomation.com/t/help-with-querytaghistory-and-intervalminutes/16785/6 "2020-02-01T01:24:00Z")

</div>

Ah! That was it. Thanks!! was throwing me for a loop.
