# Can Timestamp of a Tag be written to using a script

**URL:** <https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [January 20, 2021, 4:26pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444 "2021-01-20T16:26:41Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.mccabe](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@michael.mccabe](https://forum.inductiveautomation.com/u/michael.mccabe)\
**Post date:** [January 20, 2021, 4:26pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/1 "2021-01-20T16:26:41Z")

</div>

Hi Folks,  
Wondering if a Timestamp of a tag can be forced using scripts or any other methods?  
I want to read a timestamp from OPC, separate to another Boolean value from OPC.  
These 2 correlate, I want to write the Boolean to a memory tag, and want to force its timestamp to be the timestamp I read over OPC.  
I know this can be done using a module and would need this developed, just looking for an alternative. When I do a system tag write it creates a Custom Timestamp but I don’t believe this would be applied to an alarm, it will use actual tag timestamp.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [January 20, 2021, 4:54pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/2 "2021-01-20T16:54:39Z")

</div>

You can try writing a `QualifiedValue` directly; something like:

```auto
from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue
paths = ["path/to/tag"]
values = [1]
qvs = [BasicQualifiedValue(v) for v in values]
for qv in qvs:
    qv.timestamp = system.date.getDate(2020, 11, 25)
system.tag.writeBlocking(paths, qvs)

```

---

<div class="post-metadata">

**Author:** ![michael.mccabe](https://avatars.discourse-cdn.com/v4/letter/m/50afbb/32.png) [@michael.mccabe](https://forum.inductiveautomation.com/u/michael.mccabe)\
**Post date:** [January 26, 2021, 10:14am UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/3 "2021-01-26T10:14:57Z")

</div>

“from com.inductiveautomation.ignition.common.model.values import BasicQualifiedValue  
paths = [“path/to/tag”]  
values = [1]  
qvs = [BasicQualifiedValue(v) for v in values]  
for qv in qvs:  
value.timestamp = system.date.getDate(2020, 11, 25)  
system.tag.writeBlocking(paths, qvs)”

Thanks @paul-griffith, This worked, Only thing I had to change was value.timestamp to qv.timestamp.  
One to note for anyone else needed this is January is month 0.

---

<div class="post-metadata">

**Author:** ![harigobu.gb](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@harigobu.gb](https://forum.inductiveautomation.com/u/harigobu.gb)\
**Post date:** [February 6, 2021, 12:26pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/4 "2021-02-06T12:26:24Z")

</div>

Hi Paul, Will it work if the value didn’t changed. But there might be different timestamp.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [February 8, 2021, 5:33pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/5 "2021-02-08T17:33:52Z")

</div>

You could use the same method, you’ll just want to read the tag before you write it to leave the value unchanged. That does introduce a potential race (the value could change between your read and subsequent write) but is likely safe enough.

---

<div class="post-metadata">

**Author:** ![harigobu.gb](https://avatars.discourse-cdn.com/v4/letter/h/b77776/32.png) [@harigobu.gb](https://forum.inductiveautomation.com/u/harigobu.gb)\
**Post date:** [February 10, 2021, 4:35pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/6 "2021-02-10T16:35:36Z")

</div>

Thank you Paul… 🙏

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [May 25, 2021, 7:32pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/7 "2021-05-25T19:32:11Z")

</div>

Paul, out of curiosity, if this tag we just wrote a value (and timestamp) to is being historized, does the tag historian use this timestamp as the t\_stamp to store in the Historian database? Or does the historian use it’s own now() value when inserting upon evaluating?

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [May 25, 2021, 8:01pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/8 "2021-05-25T20:01:45Z")

</div>

In 7.9 and previous, there were separate notions of timestamp sources, but as far as I know, in 8.0+ the timestamp is basically always calculated in the historian, not ‘trusted’ from the value.

---

<div class="post-metadata">

**Author:** ![drojas](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drojas/32/3403_2.png) [@drojas](https://forum.inductiveautomation.com/u/drojas)\
**Post date:** [May 25, 2021, 8:26pm UTC](https://forum.inductiveautomation.com/t/can-timestamp-of-a-tag-be-written-to-using-a-script/42444/9 "2021-05-25T20:26:52Z")

</div>

Darn. This kindof means I’m out of luck. If I import raw tag data from a CSV file using system.tag.storeTagHistory function, I can specify the timestamp…but I lose out on the deadband optimization the Historian provides so I end up storing way more data than I need. If I instead write to the tag’s value and timestamp, I gain the deadband and alarm functionality, but the historian won’t use my timestamp.
