setTime function works but generates errors

I did see a similar post but no resolution.

I have a Memory tag that calculates the production date. For our facility the production date starts at 5:00 am, so between midnight and 5:00 am the production date is the previous day. My expression for the tag is:

If((getHour24({[System]Gateway/CurrentDateTime})>=0) && (getHour24({[System]Gateway/CurrentDateTime})< 5),
addDays(midnight({[System]Gateway/CurrentDateTime}),-1),
midnight({[System]Gateway/CurrentDateTime}))

and it works fine. Tag datatype is DateTime.

In my Perspective project I use that tag to do various calculations, for example, to calculate the first full hour of production, I create a parameter with the expression binding of:

setTime({[default]Memory/Current_Production_Date},6,0,0)

and it works and has been working for months - I use similar calculations in named queries that return correct results.

I’m troubleshooting a different error and I notice that these setTime calls are generating errors:

setTime function expected a 'date' first argument, but got null

Is there something I can do to keep these errors from generating - rewrite the expression?

Use now(5000) or similar instead of using the system tag. Tag references deliver a null in bindings and expressions as the view starts up.

Thanks for the feedback. I’ll use the now() function in the expression for the Current_Production_Date tag. Will I still get an error on my bindings that reference that tag? In other words, do I need to do the math inside each binding to avoid the error?

Yes because you haven’t corrected the issue that Phil noted.

You should create a property, perhaps a session property that does the math, then reference that property where you need it.

A property!. That’s the missing link I needed. Thank you.