# Read a historical tag value

**URL:** <https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578>\
**Category:** Ignition\
**Created:** [November 12, 2020, 1:06pm UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578 "2020-11-12T13:06:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lachguerabdallah](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lachguerabdallah/32/25558_2.png) [@lachguerabdallah](https://forum.inductiveautomation.com/u/lachguerabdallah)\
**Post date:** [November 12, 2020, 1:06pm UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578/1 "2020-11-12T13:06:26Z")

</div>

Hello

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

thanks you

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [November 12, 2020, 4:31pm UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578/2 "2020-11-12T16:31:15Z")

</div>

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

```auto
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"
)

```

---

<div class="post-metadata">

**Author:** ![lachguerabdallah](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lachguerabdallah/32/25558_2.png) [@lachguerabdallah](https://forum.inductiveautomation.com/u/lachguerabdallah)\
**Post date:** [November 13, 2020, 2:57pm UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578/3 "2020-11-13T14:57:43Z")

</div>

thanks you

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [February 3, 2021, 5:42am UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578/4 "2021-02-03T05:42:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [February 3, 2021, 5:47am UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578/5 "2021-02-03T05:47:21Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [February 3, 2021, 5:52am UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578/6 "2021-02-03T05:52:07Z")

</div>

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.

```auto
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)

```

---

<div class="post-metadata">

**Author:** ![prasath.t](https://avatars.discourse-cdn.com/v4/letter/p/898d66/32.png) [@prasath.t](https://forum.inductiveautomation.com/u/prasath.t)\
**Post date:** [February 3, 2021, 5:52am UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578/7 "2021-02-03T05:52:35Z")

</div>

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
```

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [February 3, 2021, 5:58am UTC](https://forum.inductiveautomation.com/t/read-a-historical-tag-value/40578/8 "2021-02-03T05:58:45Z")

</div>

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.
