queryTagHistory gets data beyond the specified date range

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

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

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

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.