How to get single value from a time using tag historian

I am trying to make a table that compares the current value of a tag, to the value of it from a date in the past that is selected by a datetime input. I was previously doing this with a system.tag.queryTagHistory that looked like this
system.tag.queryTagHistory(paths = getPaths,startDate = firstStart, endDate = firstEnd, returnSize = 1, aggregationMode=“LastValue”, noInterpolation = True)

I have a bunch of paths, and I just want to get what each of the tags values was at the time, so I made that time the endDate, and then a subtracted 5 hours from that and made it the startDate.
Then I returned the “LastValue” so that I get the most recent value, effectively giving me the value at the endDate which is what I want.
All I want is what the values were at that time.
Is there a better way to do this?

1 Like

The thing is that you may not have a value on an exact time. I mean, the tag history engine stores historical data based on a store rate, this can be either on each value change or in a fixed rate.
So if you ask for a value in a specific timestamp or in a short datetime range, and for that exact datetime there is not a value, then nothing will be returned.
In my opinion your approach is correct.