# If() expression question

**URL:** <https://forum.inductiveautomation.com/t/if-expression-question/84228>\
**Category:** Ignition\
**Tags:** ignition81, perspective\
**Created:** [January 12, 2024, 8:04pm UTC](https://forum.inductiveautomation.com/t/if-expression-question/84228 "2024-01-12T20:04:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [January 12, 2024, 8:04pm UTC](https://forum.inductiveautomation.com/t/if-expression-question/84228/1 "2024-01-12T20:04:25Z")

</div>

OK Im sure I have just stared at this too long but, Im curious about a return from an If statement I am using:

I have this expression tag, Current Shift:

```auto
if(21 > (dateFormat({[System]Gateway/CurrentDateTime}, "k")) >7,0,1) 

```

returning a 1.  
From there that tag is bound to a label, Current Shift Ind 2, showing its a 1.

Then another label binds to that labels .value and has a expression:

```auto
if({../Current Shift Ind 2.props.value}=1,'DAY','NIGHT')

```

but is returning 'NIGHT' instead of 'DAY'

Am I crazy? BTW, I am troubleshooting an old project from who knows who.

I was told before, that it worked and should be displaying 'DAY'. Im sure there are lots of thoughts, lol, but any help?

---

<div class="post-metadata">

**Author:** ![DNice](https://avatars.discourse-cdn.com/v4/letter/d/858c86/32.png) [@DNice](https://forum.inductiveautomation.com/u/DNice)\
**Post date:** [January 12, 2024, 8:25pm UTC](https://forum.inductiveautomation.com/t/if-expression-question/84228/2 "2024-01-12T20:25:51Z")

</div>

I tested that logic on my end and it works. Perhaps try to change the binding of Day/Night label to use the exact same logic as the first. I have seen funky things like this happend on rare occasions.

---

<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:** [January 12, 2024, 8:55pm UTC](https://forum.inductiveautomation.com/t/if-expression-question/84228/3 "2024-01-12T20:55:06Z")

</div>

`dateFormat()` produces a string, not an integer. Comparing strings with integers is probably the issue.

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [January 12, 2024, 9:42pm UTC](https://forum.inductiveautomation.com/t/if-expression-question/84228/4 "2024-01-12T21:42:00Z")

</div>

Would this be more like right? Since I would be comparing string to string..

```auto
timeBetween(dateFormat({[System]Gateway/CurrentDateTime}, "k"), "8", "20")//Boolean ON = Day

```

---

<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:** [January 12, 2024, 9:48pm UTC](https://forum.inductiveautomation.com/t/if-expression-question/84228/5 "2024-01-12T21:48:06Z")

</div>

Is there any particular reason you are avoiding [getHour()](https://docs.inductiveautomation.com/pages/viewpage.action?pageId=58603828) ?

```auto
getHour({[System]Gateway/CurrentDateTime}) >= 8 && getHour({[System]Gateway/CurrentDateTime}) <= 20

```

---

<div class="post-metadata">

**Author:** ![mjohnson0238](https://avatars.discourse-cdn.com/v4/letter/m/4bbf92/32.png) [@mjohnson0238](https://forum.inductiveautomation.com/u/mjohnson0238)\
**Post date:** [January 12, 2024, 9:52pm UTC](https://forum.inductiveautomation.com/t/if-expression-question/84228/6 "2024-01-12T21:52:08Z")

</div>

Sure was, I didnt notice it there in the listing. I see it now, lol. Thanks very helpful sir.
