# Writing current time to Memory Tag not working

**URL:** <https://forum.inductiveautomation.com/t/writing-current-time-to-memory-tag-not-working/90057>\
**Category:** Ignition\
**Tags:** perspective, scripting, ignition81\
**Created:** [May 7, 2024, 6:03pm UTC](https://forum.inductiveautomation.com/t/writing-current-time-to-memory-tag-not-working/90057 "2024-05-07T18:03:11Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Luke\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Luke\_Smith1](https://forum.inductiveautomation.com/u/Luke_Smith1)\
**Post date:** [May 7, 2024, 6:03pm UTC](https://forum.inductiveautomation.com/t/writing-current-time-to-memory-tag-not-working/90057/1 "2024-05-07T18:03:11Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/4/4/44de16d2f10d611b5eececc894ceb7e08b8f4427.png)

Hello, I'd like to write current time to a memory tag everytime I have a change in a PLC variable. I am writing the script shown in the picture above inside the PLC variable, but the memory tag is not updating. What am I doing wrong?

Any help would be greatly appreciated!

Thanks,  
Luke

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [May 7, 2024, 6:15pm UTC](https://forum.inductiveautomation.com/t/writing-current-time-to-memory-tag-not-working/90057/2 "2024-05-07T18:15:42Z")

</div>

You are checking `initialChange` too late. Check it **before** any use of `previousValue` to avoid an error that kills your script.

---

<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 7, 2024, 6:16pm UTC](https://forum.inductiveautomation.com/t/writing-current-time-to-memory-tag-not-working/90057/3 "2024-05-07T18:16:10Z")

</div>

Also, a typo - `system.data.now` is not a real function; `system.date.now` is.

---

<div class="post-metadata">

**Author:** ![Luke\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Luke\_Smith1](https://forum.inductiveautomation.com/u/Luke_Smith1)\
**Post date:** [May 7, 2024, 6:21pm UTC](https://forum.inductiveautomation.com/t/writing-current-time-to-memory-tag-not-working/90057/4 "2024-05-07T18:21:09Z")

</div>

Oh my... I've been staring straight at that typo for hours. You're a life saver. Thank you!

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [May 7, 2024, 6:29pm UTC](https://forum.inductiveautomation.com/t/writing-current-time-to-memory-tag-not-working/90057/5 "2024-05-07T18:29:57Z")

</div>

To note, at the top right of that dialog, there is a button that will show the Tag Diagnostics (Looks like an ECG line) , this would have announced the typo to you, and probably have saved you a little hair along the way.

---

<div class="post-metadata">

**Author:** ![Luke\_Smith1](https://avatars.discourse-cdn.com/v4/letter/l/c89c15/32.png) [@Luke\_Smith1](https://forum.inductiveautomation.com/u/Luke_Smith1)\
**Post date:** [May 7, 2024, 6:35pm UTC](https://forum.inductiveautomation.com/t/writing-current-time-to-memory-tag-not-working/90057/6 "2024-05-07T18:35:22Z")

</div>

Incredibly useful, thank you lrose!
