# Find if machine ran in last hour Tag Historian

**URL:** <https://forum.inductiveautomation.com/t/find-if-machine-ran-in-last-hour-tag-historian/17414>\
**Category:** Ignition\
**Created:** [March 19, 2018, 12:27pm UTC](https://forum.inductiveautomation.com/t/find-if-machine-ran-in-last-hour-tag-historian/17414 "2018-03-19T12:27:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vanko25](https://avatars.discourse-cdn.com/v4/letter/v/a87d85/32.png) [@vanko25](https://forum.inductiveautomation.com/u/vanko25)\
**Post date:** [March 19, 2018, 12:27pm UTC](https://forum.inductiveautomation.com/t/find-if-machine-ran-in-last-hour-tag-historian/17414/1 "2018-03-19T12:27:39Z")

</div>

Hello all,

I am trying to find if a machine ran in the last hour. So even if it is off now but it has ran in the last hour I am looking at getting Boolean true. I am looking at the historian of my Boolean status bit with the following piece of code but I am getting random values. Sometimes it returns 1 as it supposed sometimes it returns 0. I just want to now if in the last 60 minutes that tag was true. Could you please help? Thanks!

```auto
tagPath = "[history_provider]tag_path"
startDate = system.date.addMinutes(system.date.now(), -60)
endDate = system.date.now()
dataset = system.tag.queryTagHistory(paths=[tagPath], startDate = startDate, endDate = endDate, returnSize=1, aggregationMode="Maximum", returnFormat='Wide')	
data= dataset.getValueAt(0,1)
```

---

<div class="post-metadata">

**Author:** ![Sanderd17](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/sanderd17/32/8735_2.png) [@Sanderd17](https://forum.inductiveautomation.com/u/Sanderd17)\
**Post date:** [March 19, 2018, 12:37pm UTC](https://forum.inductiveautomation.com/t/find-if-machine-ran-in-last-hour-tag-historian/17414/2 "2018-03-19T12:37:35Z")

</div>

It look like you’re always processing row 0, while you should actually check if there’s a “True” value in that dataset.

You should also try to figure out what happens when the machine didn’t change state in that hour, and was always on or off. It’s likely you get a zero-size ds back.

---

<div class="post-metadata">

**Author:** ![vanko25](https://avatars.discourse-cdn.com/v4/letter/v/a87d85/32.png) [@vanko25](https://forum.inductiveautomation.com/u/vanko25)\
**Post date:** [March 19, 2018, 12:55pm UTC](https://forum.inductiveautomation.com/t/find-if-machine-ran-in-last-hour-tag-historian/17414/3 "2018-03-19T12:55:22Z")

</div>

Sanderd17,

I am just getting to now tag.queryTagHistory. I got what you mean now. I tought if I return 1 row it will just get me the maximum for the last hour which seems not to be the case. Thanks!
