Read a historical tag value

Hello

How can I read the value of a historical tag that has a specific date and time?

thanks you

Not a lot of information here, but this should get you the last value logged for any particular instant.

system.tag.queryTagHistory(
    [tagPath], # square brackets are important here, you need to insert your own tagpath
    startDate = specificTime,    # needs to be type java.util.date need to provide specificTime
    returnSize = 1,
    aggregationMode = "LastValue"
)

thanks you

How to use this query and show value in text field?

You probably wouldn’t use this script. I would use a tag history binding with similar parameters to the ones that are spelled out in the script.

If this is vision you may have to put the tag binding on a custom property (it will return a dataset I think). You can then use another binding on the text property to get the value out of the dataset.

If you’re using perspective, you can just use an expression transform to accomplish the same thing without the extra custom property.

If you really wanted to be able to do this from a script (again, maybe not the best way), it would look something like this for vision.

newValue = system.tag.queryTagHistory(
    [tagPath], # square brackets are important here, you need to insert your own tagpath
    startDate = specificTime,    # needs to be type java.util.date need to provide specificTime
    returnSize = 1,
    aggregationMode = "LastValue"
)
# You have to set the path to your component here. It would look something like this for vision.
event.source.parent.getComponent('Text Field').text = newValue.getValueAt(0,0)

I am new to ignition. Please explain me with sample script. I am requriment is I will explain

I have one text field where they fetching the tag  using tag browser. That tag showing tha live data. What I have to do is... I have to use text field or some component and show the last changed value and time stamp of tha tag which selected in that text field. I don't how to use this script and get the value in text field. I am new to ignition so I want some guidance please

This script snippet really only works if you already know the time you want to look at (as per the request in the original post). It sounds to me like you need a different solution altogether. I would advise you to make a new post asking about the best way to fulfill your stated goal.