# setTime function works but generates errors

**URL:** <https://forum.inductiveautomation.com/t/settime-function-works-but-generates-errors/109532>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [August 8, 2025, 1:28pm UTC](https://forum.inductiveautomation.com/t/settime-function-works-but-generates-errors/109532 "2025-08-08T13:28:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_Buehrer](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Chris\_Buehrer](https://forum.inductiveautomation.com/u/Chris_Buehrer)\
**Post date:** [August 8, 2025, 1:28pm UTC](https://forum.inductiveautomation.com/t/settime-function-works-but-generates-errors/109532/1 "2025-08-08T13:28:08Z")

</div>

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?

---

<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:** [August 8, 2025, 1:42pm UTC](https://forum.inductiveautomation.com/t/settime-function-works-but-generates-errors/109532/2 "2025-08-08T13:42:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Chris\_Buehrer](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Chris\_Buehrer](https://forum.inductiveautomation.com/u/Chris_Buehrer)\
**Post date:** [August 8, 2025, 3:56pm UTC](https://forum.inductiveautomation.com/t/settime-function-works-but-generates-errors/109532/3 "2025-08-08T15:56:22Z")

</div>

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?

---

<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:** [August 8, 2025, 4:59pm UTC](https://forum.inductiveautomation.com/t/settime-function-works-but-generates-errors/109532/4 "2025-08-08T16:59:12Z")

</div>

> [@Chris\_Buehrer](#):
>
> Will I still get an error on my bindings that reference that tag?

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

> [@pturmel](#):
>
> Tag references deliver a null in bindings and expressions as the view starts up.

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

---

<div class="post-metadata">

**Author:** ![Chris\_Buehrer](https://avatars.discourse-cdn.com/v4/letter/c/9de053/32.png) [@Chris\_Buehrer](https://forum.inductiveautomation.com/u/Chris_Buehrer)\
**Post date:** [August 8, 2025, 7:48pm UTC](https://forum.inductiveautomation.com/t/settime-function-works-but-generates-errors/109532/5 "2025-08-08T19:48:25Z")

</div>

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