I am writing a script (On a button) that will query the history tags using the "queryTagHistory" function. The dataset obtained from the query will be passed on a custom parameter on the button.
date = system.date.now()
dateMidnight = system.date.midnight(date)
startTime = system.date.addDays(dateMidnight, -8)
endTime = system.date.addHours(startTime, 24)
dataSet = system.tag.queryTagHistory(paths=['[SMYPC]Switch Gear/Substation/INCOMING FEEDER (-K101)/Energy Delivered'], startDate=startTime, endDate=endTime)
event.source.dataset = dataSet
print startTime
print endTime
The date range used on the code is:
Start Time: Tue Mar 30 00:00:00 SGT 2021
End Time: Wed Mar 31 00:00:00 SGT 2021
Upon checking the result of the dataset on the button's custom property I got an extra data which is beyond the date:
![Extra data2](https://global.discourse-cdn.com/business4/uploads/inductiveautomation/original/3X/f/8/f8a6b6d4b5ed87ff3d568b9f7653ecf4bf8f24ac.png)
I also used a power table to get the tag history with these settings:
Here is the binded date and time custom properties for the power table:
startdate: 03/30/2021 00:00:00 +0800
enddate: 03/31/2021 00:00:00 +0800
I also got the same results and got the same extra data I got on the script that I wrote on the button:
![Power table result](https://global.discourse-cdn.com/business4/uploads/inductiveautomation/original/3X/6/0/60afbdda34a24b92e772887864ef61daf5b52d32.png)
Is this a bug or am I doing something wrong?
It looks like it is grabbing the first value from the 31st since you have that as the end date.
Try setting your end date to 03/30/2021 23:59:59 and see what it returns.
Maybe a time zone issue? Just a guess since the last value shown is for 7:37am and your time zone is +8 hours.
I tried to set my date range on:
Start Date: Wed Apr 07 00:00:00 SGT 2021
End Date: Wed Apr 07 23:00:00 SGT 2021
I still get the first data from the next day:
![23 hours](https://global.discourse-cdn.com/business4/uploads/inductiveautomation/original/3X/e/7/e724b0c30a836977b446b46db53d04b796cade5f.png)
This is also shows that is not a time zone issue.
Can you increase the end date by 1 day and change the sample size to “on change” and post the result?
dataSet = system.tag.queryTagHistory(paths=['[SMYPC]Switch Gear/Substation/INCOMING FEEDER (-K101)/Energy Delivered'], startDate=startTime, endDate=endTime, returnSize=-1)
Does not work. Still has an extra data.
I already made a support ticket for this. After conversing with the support it looks like this code uses default parameters:
dataSet = system.tag.queryTagHistory(paths=['[SMYPC]Switch Gear/Substation/INCOMING FEEDER (-K101)/Energy Delivered'], startDate=startTime, endDate=endTime)
What we did was:
dataSet = system.tag.queryTagHistory(paths=['[SMYPC]Switch Gear/Substation/INCOMING FEEDER (-K101)/Energy Delivered'], startDate=startTime, endDate=endTime, intervalMinutes = 2)
Adding the “intervalMinutes” parameter solves my issue and now I am getting some data inside the specified time range.
Yea, but I wanted to see what data was returned. I was thinking it may be related to the raw data collected.