# String comparison bug

**URL:** <https://forum.inductiveautomation.com/t/string-comparison-bug/43378>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [February 12, 2021, 11:33pm UTC](https://forum.inductiveautomation.com/t/string-comparison-bug/43378 "2021-02-12T23:33:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![miketob](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/miketob/32/5936_2.png) [@miketob](https://forum.inductiveautomation.com/u/miketob)\
**Post date:** [February 12, 2021, 11:33pm UTC](https://forum.inductiveautomation.com/t/string-comparison-bug/43378/1 "2021-02-12T23:33:42Z")

</div>

I have an expression tag that makes a string comparison to determine if the current time is before or after a certain time my expression is:

```auto
dateFormat(now(),"HH:mm") < "21:30"

```

and I noticed a strange behavior when the time is from 21:00 to 21:30

so I made some tests and I simplified the expression to this simple comparison:

```auto
"21:13" < "21:30"

```

And the result is False, instead of true.

---

<div class="post-metadata">

**Author:** ![bmusson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bmusson/32/87530_2.png) [@bmusson](https://forum.inductiveautomation.com/u/bmusson)\
**Post date:** [February 12, 2021, 11:50pm UTC](https://forum.inductiveautomation.com/t/string-comparison-bug/43378/2 "2021-02-12T23:50:26Z")

</div>

You’re comparing strings when you really want to be comparing datetimes.  
So instead of converting the current time into a string, you should convert today’s 21:30 into a datetime.

```auto
now() < setTime(now(), 21, 30, 0)

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [February 12, 2021, 11:56pm UTC](https://forum.inductiveautomation.com/t/string-comparison-bug/43378/3 "2021-02-12T23:56:44Z")

</div>

> [@miketob](#):
>
> so I made some tests and I simplified the expression to this simple comparison:
> 
> ```auto
> "21:13" < "21:30"
> 
> ```

As @bmusson mentioned, you're doing a comparison on Strings here, and the expression language will attempt to coerce these to numbers before giving up all together.

In this case your comparison ends up being `21.0 < 21.0`, resulting in `false`.

---

<div class="post-metadata">

**Author:** ![miketob](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/miketob/32/5936_2.png) [@miketob](https://forum.inductiveautomation.com/u/miketob)\
**Post date:** [February 13, 2021, 1:40am UTC](https://forum.inductiveautomation.com/t/string-comparison-bug/43378/4 "2021-02-13T01:40:38Z")

</div>

hummm, ok, that’s kind of a gotcha.

Thanks a lot Kevin and Ben
