Capture current date and time into a memory tag

Is there a simple expression to move the current date and time into a memory tag? I just want a PLC bit to trigger a time capture. I see there is something called now() and I can trigger that to happen but since an if statement needs a false condition, I'm trying to copy that now() into another memory tag and it isn't work. There has to be an easy way to do this.

Gateway tag change event that points at the trigger bit in question, write the value of system.date.now() to the appropriate storage tag.

Thanks Ryan, Any examples on how that's done? I've heard of scripts or expressions in the gateway itself but haven't done that yet. Thanks.

That manual link should cover basic setup of a gateway tag change event, it also has a link to a free video in there as well.

As for the script in the gateway tag change event, it would be something along the lines of

# Catch rising edge of transition from false to true
if not previousValue.value and newValue.value:
    system.tag.writeBlocking(['Path/To/Storage/Tag'], [system.date.now()])

If you need this for multiple PLCs you can modify the script to build the path to the storage tag based on the path of the tag that triggered the event.

What does this mean:

Due to their nature, Client Tags will not trigger Gateway Tag Change Scripts. However, Client Event Scripts enable you to trigger a script based on a Client Tag changing value.

Right now for testing I'm using a test bit in ignition not a plc bit and it doesn't seem to work. Am I doing it wrong or does it indeed need to be a plc tag?

Client tags are specific to Vision Clients, and exist only on the client machine which is why they cannot trigger a Gateway Tag Change event.

What tag provider is your test tag listed under. If it's under [Client] then its in the wrong place.

It does not need to be a PLC tag, you can use a memory tag on your gateway. If possible show how your Gateway script and test tag are configured.

I'm using perspective and the default tag provider. I created a memory tag of type datetime and it doesn't matter what I try, it doesn't work. I tried your method, I tried putting a script on that tag itself under edit tag, I tried putting a script on the trigger tag. This is very frustrating so something that should be so simple.

In perspective a created a boolean memory tag and called it trigger. I also created a datetime memory tag and called it date. If I edit the trigger tag and go to scripting and value changed and type this:

system.tag.writeBlocking(
    ["[default]date"],
    [system.date.now()]
)



Then it'll record the current date. However it'll record the date when the trigger is true and then again when the trigger is false. If I put an IF statement in front of that it won't fire at all. It doesn't matter what I use in the IF statement, the script just doesn't fire.

Irrelevant, tags exist outside of the modules, with the exception of Vision Client Tags

Do you get an error in the logs with the if statement present? If so, what is the error that you get? What is the if statement you put in front of it?

Wrong spot you need a GATEWAY Tag Change event

Also, i just realized my if statement was using the wrong member for the latest value in a gateway tag change script, it should be newValue.value not currentValue.value. I have corrected my example

Are you getting an error indicator on the side of the code? This works just fine as a tag change script that only fires on True and also good quality.

if not initialChange and currentValue.quality.isGood() and currentValue.value:
    system.tag.writeBlocking(["[default]path/to/plcTime"], [system.date.now()])

Yes. As soon as I type the word if I get a little red tick mark on the right of the code. Again it doesn't matter if I write the script in the gateway or on the tag itself. So far the only somewhat luck I've had is the very basic script I pasted above. Which again isn't the answer I'm looking for but since I'm running out of hair to pull out, on the final product, I may just turn a plc bit on for a second or two. Then the final result will be a date and time that's off by a few seconds since the script will fire twice. A few seconds off on a several hour process should be acceptable.

Hover over the red tick and it'll tell you the compile error. It appears when you type if because until the full If statement is written its invalid. If you're getting it with some of the supplied code here then most likely it's a missing indentation issue.

There was a bug for event scripts:

This was more of an annoyance than anything actually wrong. There was a workaround here:

This is fixed in 8.3.9, released a few days ago.