How to get Latest Timestamp of Tag

Hi,

Is there a "direct" way to get the timestamp of the latest row return by queryTagHistory?
The not so direct way is to query with some arbitrary range.

Background:

I have a Discrete Tag.
This Tag has timestamp property, but I do not want to get this timestamp.
When this tag quality changes it will update this timestamp property of Tag.

What I do want is, the timestamp of the last change which is stored in the (latest row) historian table.

I think you're bumping into another limitation of the Historian.

Generally when configuring tag history you'll set the Max Time Between Samples so that you don't have extended periods of time in tag history with no record of the tag. This might be once every day for monthly pruning, etc.

The problem now is that the latest value isn't the last change. It may never change but there will be a reading every time Max Time elapses.

It may be time to do your own logging or create a DateTime memory tag to be updated every time the original tag changes state.

In this case, I am good, because the nature of this data is discrete. So the historian will log the value every time it change.

Just thinking if there is a built in function I can use, like "select top 1". - i guess this is the solution, to write a sql select query on the historian.

But you are right, a robust option is to create a logging mechanism myself.

If your Historian configuration uses pruning this gets messy very quickly as the data is split across monthly tables.

you are right, I need to know the table name, as it changed from time to time.

:thinking:
If I log myself, I need to setup a pruning logic for my table.. which is above my experience.

I guess back to using system.tag.queryTagHistory

The pruning logic could be as simple as a gateway scheduled task to run a query once a day (or whatever) to delete all records older than one year (or whatever). And you have a year to figure it out!

1 Like