# Weird Comparison

**URL:** <https://forum.inductiveautomation.com/t/weird-comparison/36431>\
**Category:** Ignition\
**Created:** [July 7, 2020, 1:18pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431 "2020-07-07T13:18:18Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [July 7, 2020, 1:18pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/1 "2020-07-07T13:18:18Z")

</div>

I have a number that I wish to test against a lower value and an upper number.

```auto
theTime = system.tag.read('[System]Gateway/CurrentDateTime') 
system.tag.write('[default]Events/ALARMS/CurrentHour',int(system.db.dateFormat(theTime.value, 'HH'))) 
system.tag.write('[default]Events/ALARMS/CurrentMinute',int(system.db.dateFormat(theTime.value, 'mm'))) 
system.tag.write('[default]Events/ALARMS/CurrentSecond',int(system.db.dateFormat(theTime.value, 'sif qv.value >= 8 and qv.value <= 19:
 system.tag.ws')))

event_time_hour = system.tag.read('[default]Events/ALARMS/CurrentHour') 
event_time_minute = system.tag.read('[default]Events/ALARMS/CurrentMinute')
event_time_second = system.tag.read('[default]Events/ALARMS/CurrentSecond')

sftreport = system.tag.read('[default]Events/ALARMS/CurrentHour') 

if sftreport.value >= 8 and sftreport.value <= 19:
      system.tag.write('Events/ALARMS/Shift', 'Day') 

```

My current Hour is 9  
When I run the script in the Console, it returns a ‘2’, but the ‘Events/ALARMS/Shift’ tag does not change.

Weirdness: This works.  
if sftreport.value \>= 8 :  
system.tag.write(‘Events/ALARMS/Shift’, ‘Day’)

This does not work.  
if sftreport.value \<= 19 :  
system.tag.write(‘Events/ALARMS/Shift’, ‘Day’)

Help???

---

<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:** [July 7, 2020, 1:36pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/2 "2020-07-07T13:36:42Z")

</div>

Change those write calls to writeSynchronous or writeBlocking depending on what version of Ignition you are on and then add some print statements before the comparison for debugging.

---

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [July 7, 2020, 3:05pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/3 "2020-07-07T15:05:31Z")

</div>

OKAY

```auto
theTime = system.tag.read('[System]Gateway/CurrentDateTime') 

print theTime

system.tag.writeSynchronous('[default]Events/ALARMS/CurrentHour',int(system.db.dateFormat(theTime.value, 'HH'))) 

print system.tag.writeSynchronous

system.tag.writeSynchronous('[default]Events/ALARMS/CurrentMinute',int(system.db.dateFormat(theTime.value, 'mm'))) 

print system.tag.writeSynchronous

system.tag.writeSynchronous('[default]Events/ALARMS/CurrentSecond',int(system.db.dateFormat(theTime.value, 'ss')))

print system.tag.writeSynchronous

event_time_hour = system.tag.read('[default]Events/ALARMS/CurrentHour') 

print event_time_hour

event_time_minute = system.tag.read('[default]Events/ALARMS/CurrentMinute')
event_time_second = system.tag.read('[default]Events/ALARMS/CurrentSecond')

sftreport = system.tag.read('[default]Events/ALARMS/CurrentHour')

print sftreport

if sftreport.value >= 8 and sftreport.value <= 19:
	print 'Day'
	system.tag.write('[default]Events/ALARMS/Shift', 'Day')

```

The Response is:

```auto
>>> 
[Tue Jul 07 11:01:12 EDT 2020, Good, Tue Jul 07 11:01:12 EDT 2020 (1594134072446)]
<java function writeSynchronous 0x2>
<java function writeSynchronous 0x2>
<java function writeSynchronous 0x2>
[11, Good, Tue Jul 07 11:00:27 EDT 2020 (1594134027287)]
[11, Good, Tue Jul 07 11:00:27 EDT 2020 (1594134027287)]
>>>

```

I do not get an error.

---

<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:** [July 7, 2020, 3:35pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/4 "2020-07-07T15:35:36Z")

</div>

Can you add one like this:

```auto
print type(sftreport.value)

```

---

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [July 7, 2020, 3:54pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/5 "2020-07-07T15:54:34Z")

</div>

Sure Thing

```auto
Event_Time = system.tag.read('[System]Gateway/CurrentDateTime') 

print Event_Time

system.tag.writeSynchronous('[default]Event/ALARMS/CurrentHour',int(system.db.dateFormat(Event_Time.value, 'HH'))) 

print system.tag.writeSynchronous

system.tag.writeSynchronous('[default]Event/ALARMS/CurrentMinute',int(system.db.dateFormat(Event_Time.value, 'mm'))) 

print system.tag.writeSynchronous

system.tag.writeSynchronous('[default]Event/ALARMS/CurrentSecond',int(system.db.dateFormat(Event_Time.value, 'ss')))

print system.tag.writeSynchronous

event_time_hour = system.tag.read('[default]Event/ALARMS/CurrentHour') 

print event_time_hour
event_time_minute = system.tag.read('[default]Event/ALARMS/CurrentMinute')
event_time_second = system.tag.read('[default]Event/ALARMS/CurrentSecond')

sftreport = system.tag.read('[default]Event/ALARMS/CurrentHour')

print sftreport
print sftreport.value

if sftreport.value >= 8 and sftreport.value <= 19: 
	print 'Day'
	system.tag.write('[default]Event/ALARMS/Shift', 'Day')

```

And the reply:  
[Tue Jul 07 11:49:50 EDT 2020, Good, Tue Jul 07 11:49:50 EDT 2020 (1594136990038)]  
\<java function writeSynchronous 0x2\>  
\<java function writeSynchronous 0x2\>  
\<java function writeSynchronous 0x2\>  
[11, Good, Tue Jul 07 11:00:27 EDT 2020 (1594134027287)]  
[11, Good, Tue Jul 07 11:00:27 EDT 2020 (1594134027287)]  
11

---

<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:** [July 7, 2020, 3:55pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/6 "2020-07-07T15:55:34Z")

</div>

That’s not what I asked for…

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [July 7, 2020, 4:13pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/7 "2020-07-07T16:13:24Z")

</div>

Kevin is attempting to check the type of the tag you are reading/writing to because he suspects it is a String tag. I can’t explain why you found that one comparison works, but Kevin’s theory would explain the general issue:

 ![Screen Shot 2020-07-07 at 9.11.20 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/f/cfee126679e423d46ff0cafb564b52fa07d3a3d5.png)  
 ![Screen Shot 2020-07-07 at 9.13.39 AM](https://us1.discourse-cdn.com/inductiveautomation/original/3X/f/f/ffe42f7e9283652af3ae6ff4af8d2c66a387cb7d.png)

---

<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:** [July 7, 2020, 4:22pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/8 "2020-07-07T16:22:42Z")

</div>

Because:

```auto
Python 2.7.16 (default, Apr 17 2020, 18:29:03)
[GCC 4.2.1 Compatible Apple LLVM 11.0.3 (clang-1103.0.29.20) (-macos10.15-objc- on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> print '11' >= 8
True
>>> print '11' <= 19
False

```

---

<div class="post-metadata">

**Author:** ![twstevic](https://avatars.discourse-cdn.com/v4/letter/t/a183cd/32.png) [@twstevic](https://forum.inductiveautomation.com/u/twstevic)\
**Post date:** [July 7, 2020, 5:23pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/9 "2020-07-07T17:23:29Z")

</div>

```auto
>>> print int('11') >= 8
True
>>> print int('11') <= 19
True
>>> 

```

Thank You.  
Very odd that the compare works one way but not the other.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [July 7, 2020, 5:32pm UTC](https://forum.inductiveautomation.com/t/weird-comparison/36431/10 "2020-07-07T17:32:39Z")

</div>

That’s because it’s looking at the ordinal values in the string

```auto
print(ord('1'))
>>> 49

```

I would verify that the tags you’re using are Integer tags. If they must be String tags, then change your comparison to:

```auto
if 8 <= int(sftreport.value) <= 19:

```
