# System.date.now() crashes binding

**URL:** <https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [July 11, 2024, 4:40pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098 "2024-07-11T16:40:36Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colby\_Desselles](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@Colby\_Desselles](https://forum.inductiveautomation.com/u/Colby_Desselles)\
**Post date:** [July 11, 2024, 4:40pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/1 "2024-07-11T16:40:36Z")

</div>

This error happens on two of my views and it happens sporadically, the binding will persist to being null even when the propertybinding value changes but the binding preview will not error out. Any ideas on why a system.date.now() would error out like this

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/3/6/3619da19db415f70e4b81a0ca34d1dcbb1454ce5.png)

---

<div class="post-metadata">

**Author:** ![Bushmatic](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bushmatic/32/87014_2.png) [@Bushmatic](https://forum.inductiveautomation.com/u/Bushmatic)\
**Post date:** [July 11, 2024, 5:18pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/2 "2024-07-11T17:18:06Z")

</div>

What's going on over yonder? That's 'None' right?

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/6/5/6567bb7a9f2dc1850309581e7fcb3474392df4d5.png)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 11, 2024, 5:18pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/3 "2024-07-11T17:18:07Z")

</div>

Not sure why that is giving you a problem, but why not use the timestamp that's already given to you in the transform?

---

<div class="post-metadata">

**Author:** ![Colby\_Desselles](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@Colby\_Desselles](https://forum.inductiveautomation.com/u/Colby_Desselles)\
**Post date:** [July 11, 2024, 5:23pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/4 "2024-07-11T17:23:10Z")

</div>

Correct that is None, but i dont believe that is causing the error as i have the same error on another screen where the line that errors is strictly: now = system.date.now()

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [July 11, 2024, 5:26pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/5 "2024-07-11T17:26:32Z")

</div>

Your transform could be simplified to just this also:

```python
return value > system.date.now() and self.view.custom.newStatus != None

```

---

<div class="post-metadata">

**Author:** ![djs](https://avatars.discourse-cdn.com/v4/letter/d/e47774/32.png) [@djs](https://forum.inductiveautomation.com/u/djs)\
**Post date:** [July 11, 2024, 5:29pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/6 "2024-07-11T17:29:03Z")

</div>

You could also replace this with an expression binding:

```python
view.custom.dateTimePickerValues.selectedDateTime > now() && self.view.custom.newStatus != null

```

---

<div class="post-metadata">

**Author:** ![michael.flagler](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/michael.flagler/32/26272_2.png) [@michael.flagler](https://forum.inductiveautomation.com/u/michael.flagler)\
**Post date:** [July 11, 2024, 5:29pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/7 "2024-07-11T17:29:33Z")

</div>

When it's giving you the error, what is the selectedDateTime value? Is it null and maybe just giving a misleading error?

---

<div class="post-metadata">

**Author:** ![Colby\_Desselles](https://avatars.discourse-cdn.com/v4/letter/c/3be4f8/32.png) [@Colby\_Desselles](https://forum.inductiveautomation.com/u/Colby_Desselles)\
**Post date:** [July 11, 2024, 5:31pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/8 "2024-07-11T17:31:14Z")

</div>

Yeah I switched it to a  
**from datetime import datetime  
today = datetime.now()** and i cant replicate the error again but i mainly was concerned about the date.now because ive used it a lot in the past and was worried if this would continue to popup errors

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 11, 2024, 5:35pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/9 "2024-07-11T17:35:28Z")

</div>

I would use the expression, but if you want the transform you already have a timestamp provided.  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/7/77d36f894aa7e326c0050ff37d4100e51b3b7034.png)

```python
if value > timestamp and ...:
    return True

```

---

<div class="post-metadata">

**Author:** ![peter](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@peter](https://forum.inductiveautomation.com/u/peter)\
**Post date:** [July 11, 2024, 5:53pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/10 "2024-07-11T17:53:47Z")

</div>

> [@dkhayes117](#):
>
> ```python
> if value > timestamp and ...:
> return True
> 
> ```

Ughh .. that's an anti pattern.

IMHO you should

> return (value \> timestamp and ...)

---

<div class="post-metadata">

**Author:** ![dkhayes117](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/dkhayes117/32/68344_2.png) [@dkhayes117](https://forum.inductiveautomation.com/u/dkhayes117)\
**Post date:** [July 11, 2024, 5:58pm UTC](https://forum.inductiveautomation.com/t/system-date-now-crashes-binding/93098/11 "2024-07-11T17:58:24Z")

</div>

I was just correcting what he was already using so it would be clear. 🤷‍♂️
