[System]Gateway/CurrentDateTime and now() different values

I would have put this message in the original thread here

(getting a Gateway script to run every minute exactly on the minute)

but it’s locked as I’d marked it as solved.

I followed JordanCClark’s advice, basically creating a tag that holds the minute value
using dateExtract(now(),“Minute”) with a fast update rate (250ms).

I’ve got an On Change script looking at this.

The issue I’ve got is that if in my script I reference [System]Gateway/CurrentDateTime
then I’m getting a value just fractionally before the change in minute.

E.g. say I expect my script to trigger at exactly 7:00:00 the value returned is 6:59:59.844

(this causes me a problem as it’s relating to detecting a shift change which happens at 7am)

So my question boils down to the expression function now() and the tag [System]Gateway/CurrentDateTime
returning different values
. It’s all on the gateway so I assumed they’d be using the same clock.

Presumably this is some timing issue?

I’ve tried changing my expression from




I think this should sort my problem although I’m finding the value now returned within the script
is typically 800ms after the minute change - ultimately not a problem although I’d have thought with
a scan class of 250ms it would have been less.

The problem is that the value for [System]Gateway/CurrentDateTime is not read from the clock every time something in the system reads that tag value. It’s simply updated with a bunch of other gateway system tags by a task that runs every second. So while you’ll probably see at least one update for every second of every hour on that tag, if some hiccup in the system ever resulted in that task running late you’d miss it.

In your script try using Python’s date/time functions to get the current time instead, it should be more accurate.