# Two timestamps for one value

**URL:** <https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984>\
**Category:** Ignition\
**Tags:** ignition81\
**Created:** [November 16, 2023, 1:50pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984 "2023-11-16T13:50:58Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jim\_Perks](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Jim\_Perks](https://forum.inductiveautomation.com/u/Jim_Perks)\
**Post date:** [November 16, 2023, 1:50pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/1 "2023-11-16T13:50:58Z")

</div>

I have setup a expression tag history as in picture, however, when I query the results I am getting two timestamps and two values for the same tag.

 ![History Setup](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/9/89a259d6230864843b449f621ca5468a9f8a7040.png)

So every time there is a value change there is a higher value number first and then the "correct" number that I see in the tag browser.

 ![dual results](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/b/8b1bc3371c4a57254df0de479219bc395c3c38b1.png)

Any thoughts why I see these two time stamps and one higher value? I thought I have interpolation off with the setup, but maybe I do not?

---

<div class="post-metadata">

**Author:** ![Jim\_Perks](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Jim\_Perks](https://forum.inductiveautomation.com/u/Jim_Perks)\
**Post date:** [November 21, 2023, 10:54am UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/2 "2023-11-21T10:54:42Z")

</div>

Anyone? 🙂 Maybe I am asking the question wrong, please let me know if any clarification is needed.

Here is another screen shot. Two values for the same timestamp.

 ![tagid421](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/0/80c70c7b8fd7b1c197c872e48f5ac9cadf9d7355.png)

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [November 21, 2023, 11:08am UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/3 "2023-11-21T11:08:15Z")

</div>

How is the tag's value source configured ? I mean, can you show the expression used to generate the value ?

---

<div class="post-metadata">

**Author:** ![Jim\_Perks](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Jim\_Perks](https://forum.inductiveautomation.com/u/Jim_Perks)\
**Post date:** [November 21, 2023, 11:57am UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/4 "2023-11-21T11:57:19Z")

</div>

Yes, here is the expression

 ![tagid421a](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/6/2639770f72309788ed2c7b3cbaca113a04e0f5b3.png)

Here is the tag and what I see as the float value.

 ![tagid421b](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/1/d1d23022089e01a7a4ad901c133f64b443a444c4.png)

the expression is

(millisBetween ({[.]Cycle Time Stop.value},{[.]Cycle Time Start.value}))/1000

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 21, 2023, 12:17pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/5 "2023-11-21T12:17:12Z")

</div>

Have you got some code changing `Cycle Time Start` and `Cycle Time Stop` simultaneously? If so then your expression might be firing twice - once for each tag change.

---

<div class="post-metadata">

**Author:** ![Jim\_Perks](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Jim\_Perks](https://forum.inductiveautomation.com/u/Jim_Perks)\
**Post date:** [November 21, 2023, 12:50pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/6 "2023-11-21T12:50:38Z")

</div>

On the Cycle Time Start I have this script:

```
if currentValue.value !=previousValue:
	value = previousValue
	system.tag.writeBlocking("[default]Line F Traub/Cycle Times/Cycle Time Stop", [value])

```

So it does look like it is reading the current and previous value.

Any thoughts on how to only read one value? Write the "previous cycle time" value to another memory tag?

---

<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:** [November 21, 2023, 12:56pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/7 "2023-11-21T12:56:57Z")

</div>

> [@Jim\_Perks](#):
>
> `if currentValue.value !=previousValue:`

This is always true, unless you made a typo.

`currentValue.value` is a true value (int,string, float, etc....) while `previousValue` is a QualifiedValue object, they are never equivalent.

You should also filter for initial change

It should be:

```python
if not initialChange and currentValue.value != previousValue.value:

```

Not filtering for initialChange means that anytime the tag resets you will also run this tag write. So save edits to the tag, restart the gateway, etc...

---

<div class="post-metadata">

**Author:** ![Jim\_Perks](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Jim\_Perks](https://forum.inductiveautomation.com/u/Jim_Perks)\
**Post date:** [November 21, 2023, 5:43pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/8 "2023-11-21T17:43:43Z")

</div>

Yes, thank you for catching that oversight. I did add the not initialChange, however, it still is adding the previous value to the current value.

```
if not initialChange and currentValue.value != previousValue.value:
	value = previousValue.value
	system.tag.writeBlocking("[default]Line F Traub/Shift Data/First Shift /Cycle Times/Cycle Time Stop", [value])

```

 ![tagid421c](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/5/95bb724447bb0d90c096d12b7b985717e04aeff9.png)

The 9.017 adds to the 6.013 and then I get that 15.03.

So the way I wrote the cycle time recording does not work well with storing the value for averaging 🙂

Here is how I calculate it. It works, but not for reading from the SQL DB because I read the two values.

**Step 1**

# Cycle Time

```
if currentValue.value != previousValue.value:
	Start = system.date.now()
	system.tag.writeBlocking(["[default]Line F Traub/Shift Data/First Shift /Cycle Times/Cycle Time Start"],[Start]) 

```

**Step 2**

```python
	if not initialChange and currentValue.value != previousValue.value:
		value = previousValue.value
		system.tag.writeBlocking("[default]Line F Traub/Shift Data/First Shift /Cycle Times/Cycle Time Stop", [value])

```

**Step 3**  
Previous Cycle Time

```python

if({[.]../../What Shift Is Active.value}=1,(millisBetween ({[.]Cycle Time Stop.value},{[.]Cycle Time Start.value}))/1000,'')

```

@Transistor ok sorry, bad 🙂 forgot to format ...good now

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [November 21, 2023, 5:45pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/9 "2023-11-21T17:45:23Z")

</div>

Format the code, Jim. Format the code! \</\>

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [November 21, 2023, 6:33pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/10 "2023-11-21T18:33:27Z")

</div>

Make it a memory tag instead of expression tag. Use the script to write everything at once.

```python
if not initialChange and currentValue.value != previousValue.value:
	
	cycleTime = system.date.millisBetween(previousValue.value, currentValue.value)/1000.0
	
	tagsOut = ["[default]Line F Traub/Cycle Times/Cycle Time Stop",
	           "[default]Line F Traub/Cycle Times/Previous Cycle Time"
	          ]

	system.tag.writeBlocking(tagsOut, [previousValue.value, cycleTime])

```

---

<div class="post-metadata">

**Author:** ![Jim\_Perks](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Jim\_Perks](https://forum.inductiveautomation.com/u/Jim_Perks)\
**Post date:** [November 21, 2023, 8:32pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/12 "2023-11-21T20:32:38Z")

</div>

That worked! 🙂  
Learned about the tagsout aspect as well. I did not know you could do that.

Thanks again!

---

<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:** [November 22, 2023, 2:08pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/13 "2023-11-22T14:08:29Z")

</div>

> [@Jim\_Perks](#):
>
> I did not know you could do that.

Not only can you do it, but you should always do it that way. It is **much** more performant to write all tags at once, then to write one at a time.

---

<div class="post-metadata">

**Author:** ![Jim\_Perks](https://avatars.discourse-cdn.com/v4/letter/j/ec9cab/32.png) [@Jim\_Perks](https://forum.inductiveautomation.com/u/Jim_Perks)\
**Post date:** [November 22, 2023, 2:24pm UTC](https://forum.inductiveautomation.com/t/two-timestamps-for-one-value/81984/14 "2023-11-22T14:24:26Z")

</div>

Absolutely agree and thank you!!  
I am actually making edits this morning on other cycle timers based on what I have learned in this thread. Much more efficient with what I have learned in the last 24 hours 🙂
