# \[feature-9009\]system.tag.queryTagHistory() - Interval less than 1 minute

**URL:** <https://forum.inductiveautomation.com/t/feature-9009-system-tag-querytaghistory-interval-less-than-1-minute/33190>\
**Category:** General Discussion\
**Tags:** scripting\
**Created:** [March 18, 2020, 4:10am UTC](https://forum.inductiveautomation.com/t/feature-9009-system-tag-querytaghistory-interval-less-than-1-minute/33190 "2020-03-18T04:10:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathan.dehoog](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nathan.dehoog/32/11903_2.png) [@nathan.dehoog](https://forum.inductiveautomation.com/u/nathan.dehoog)\
**Post date:** [March 18, 2020, 4:10am UTC](https://forum.inductiveautomation.com/t/feature-9009-system-tag-querytaghistory-interval-less-than-1-minute/33190/1 "2020-03-18T04:10:37Z")

</div>

I have been using the system.tag.queryTagHistory() function for a little while now.  
Generally I have used it on the ‘Ignition’ Tag Historian data to return tag history interpolated at a minimum interval of 1 minute or at the scan rate of the specified tag path/s.

I now have a requirement to return interpolated historical data from an OPC-HDA server at intervals less than 1 minute, in this case, 15 seconds.

I know Ignition can retrieve and interpolate historical data from the OPC-HDA server at a 15 second interval because I was able to do so with the tag history binding on a table and chart in Vision and Perspective. However, when i use the system,util.queryTagHistory() function, it will only give me a minimum interval of 1 minute (Example script below).

```auto
args = {
			'paths':['[OPC-HDA]Some Tag'],
			'returnFormat':'Wide',
			'aggregationMode':'LastValue',
			'intervalMinutes':1,
			'rangeMinutes':5,
			'endDate':system.date.now(),
			'noInterpolation':False,
			'returnSize':-1
		}
	
result = system.tag.queryTagHistory(**args)

```

Is it possible to return interpolated historical data with an interval less than 1 minute using the system,util.queryTagHistory, if so, then how?

---

<div class="post-metadata">

**Author:** ![bpreston](https://avatars.discourse-cdn.com/v4/letter/b/4af34b/32.png) [@bpreston](https://forum.inductiveautomation.com/u/bpreston)\
**Post date:** [March 18, 2020, 1:22pm UTC](https://forum.inductiveautomation.com/t/feature-9009-system-tag-querytaghistory-interval-less-than-1-minute/33190/2 "2020-03-18T13:22:28Z")

</div>

If you set your ‘returnSize’ based on your range and interval it should give you want you want. Where you are looking at a 5 minute range. set it to 20 instead of -1. -1 will return values on change. Setting it to 20 you will get 20 results evenly space so a 15 second interval over 5 minutes.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [March 18, 2020, 4:03pm UTC](https://forum.inductiveautomation.com/t/feature-9009-system-tag-querytaghistory-interval-less-than-1-minute/33190/3 "2020-03-18T16:03:41Z")

</div>

There’s a longstanding ticket to add `intervalSeconds`/`rangeSeconds` to the queryTagHistory function that I’ve added you to. We’re also planning to introduce a few new, simplified functions for specific types of history queries - they’ll still be doing the same thing as queryTagHistory, but specifically designed for, say, retrieving the value at a particular timestamp without having to specify all the arguments manually.

---

<div class="post-metadata">

**Author:** ![tordvd](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/tordvd/32/11525_2.png) [@tordvd](https://forum.inductiveautomation.com/u/tordvd)\
**Post date:** [March 18, 2020, 7:10pm UTC](https://forum.inductiveautomation.com/t/feature-9009-system-tag-querytaghistory-interval-less-than-1-minute/33190/4 "2020-03-18T19:10:58Z")

</div>

Here is the code @bpreston talked about, if you want to specify the sample time in seconds:

```auto
def getHistoryDataset(PATHS,startDate,endDate,intervalSeconds,returnSize,aggregationMode,timeout):
	endTime = endDate
	startTime = startDate
	aggregationMODE=aggregationMode
	
	# Query historian 
	
	secondsBetween = system.date.secondsBetween(startTime,endTime)
	returnSize = secondsBetween/intervalSeconds+intervalSeconds
	dataSet = system.tag.queryTagHistory(paths=PATHS, startDate=startTime, endDate=endTime, returnSize=returnSize, aggregationMode=aggregationMODE, returnFormat='Wide',timeout=timeout)

```

---

<div class="post-metadata">

**Author:** ![nathan.dehoog](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nathan.dehoog/32/11903_2.png) [@nathan.dehoog](https://forum.inductiveautomation.com/u/nathan.dehoog)\
**Post date:** [April 1, 2020, 7:44pm UTC](https://forum.inductiveautomation.com/t/feature-9009-system-tag-querytaghistory-interval-less-than-1-minute/33190/5 "2020-04-01T19:44:02Z")

</div>

Thanks all, I appreciate all the responses and have been able to make it work in my case.
