# How to get working Hours base on Boolean status

**URL:** <https://forum.inductiveautomation.com/t/how-to-get-working-hours-base-on-boolean-status/50364>\
**Category:** Ignition\
**Tags:** ignition79\
**Created:** [August 26, 2021, 11:02pm UTC](https://forum.inductiveautomation.com/t/how-to-get-working-hours-base-on-boolean-status/50364 "2021-08-26T23:02:16Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [December 11, 2022, 5:27pm UTC](https://forum.inductiveautomation.com/t/how-to-get-working-hours-base-on-boolean-status/50364/3 "2022-12-11T17:27:51Z")

</div>

Use a transaction group that has an on-change trigger for the boolean or integer of interest. Have the transaction group check the trigger as a pace that meets your accuracy requirements. Then query the database, using a LEAD() window function to look forward from an event to grab the timestamp of the next one. Use an outer query to compute the durations grouped by event value, discarding the grouped rows that aren't interesting.

The insertions into the database can also be scripted if the SQL Bridge module is not installed/licensed.

There are numerous topics on this forum with sample SQL to convert events into durations. Some of these, perhaps:

[https://forum.inductiveautomation.com/search?q=%20lead%20downtime%20order%3Alatest](https://forum.inductiveautomation.com/search?q=%20lead%20downtime%20order%3Alatest)

Also, @Shaheryar_Ahmad, you asked this question in another topic:

> [@Multiple Tag Event Scripts Running Continuously and Not Breaking a/c to its logic](https://forum.inductiveautomation.com/t/multiple-tag-event-scripts-running-continuously-and-not-breaking-a-c-to-its-logic/67464):
>
> Hi Everyone, Hope you all are doing well. I am facing a weird issue on doing scripting work on 'Tag Event Script (on Value Change)'. Help and Guide needed for resolving it. My Task I have a expression tag of machine's tower light running ON/OFF status. I want to record its ON state duration, like how much time in minutes the light has been in ON state, into a separate memory tag named 'Running\_duration'. The duration will be recorded in minutes only if the running light state exceeds more t…

---

_[View the full topic](https://forum.inductiveautomation.com/t/how-to-get-working-hours-base-on-boolean-status/50364)._
