# How to count minutes into shift?

**URL:** <https://forum.inductiveautomation.com/t/how-to-count-minutes-into-shift/113824>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [February 6, 2026, 9:03pm UTC](https://forum.inductiveautomation.com/t/how-to-count-minutes-into-shift/113824 "2026-02-06T21:03:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![amr.lamsal](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@amr.lamsal](https://forum.inductiveautomation.com/u/amr.lamsal)\
**Post date:** [February 6, 2026, 9:03pm UTC](https://forum.inductiveautomation.com/t/how-to-count-minutes-into-shift/113824/1 "2026-02-06T21:03:10Z")

</div>

How do I count minutes/hours into current shift? What is wrong with this script that runs in tag history binding ‘Most recent’ expression editor.

def getMinutesIntoShift():  
now = system.date.now()

```python
today730am = system.date.setTime(now, 7, 30, 0)
today730pm = system.date.setTime(now, 19, 30, 0)

if today730am <= now < today730pm:
    shiftStart = today730am
else:
    if now < today730am:
        shiftStart = system.date.addDays(today730pm, -1)
    else:
        shiftStart = today730pm

minutesIntoShift = system.date.minutesBetween(shiftStart, now)
return int(minutesIntoShift)

```

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/9/1/91af773136c8d07295a13f0519ab40e41983b818.png)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [February 6, 2026, 10:27pm UTC](https://forum.inductiveautomation.com/t/how-to-count-minutes-into-shift/113824/2 "2026-02-06T22:27:00Z")

</div>

You've written a [python](https://www.docs.inductiveautomation.com/docs/8.1/platform/scripting/python-scripting) function definition in something that is expecting an [expression](https://www.docs.inductiveautomation.com/docs/8.1/platform/expression-language-and-syntax).

I would recommend converting that into a proper expression and placing that expression onto a custom view property. Call it something along the lines of `shiftStartTs` or similar. Then, bind the value for `most Recent` in the history binding to that custom property.

You might run into issues with multiple calls to `now` in the same expression, so I would recommend creating another custom property called `currentTs` or similar, and referencing that in your main expression binding.

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [February 7, 2026, 1:33am UTC](https://forum.inductiveautomation.com/t/how-to-count-minutes-into-shift/113824/3 "2026-02-07T01:33:43Z")

</div>

Try this expression:

```python
floor( // get integer value of minutes
	(now(10000) - 7.5 * 3600 * 1000) // now - 7.5 hours
	% (12 * 3600 * 1000) // modulo 12 hours
	/ 60000 // divided by 60 s.
)

```

Notes:

- `now(10000)` causes it to update the minutes every 10 s (if there is a change). Make it smaller if required.
- Since they're 12 hour shifts, you only need to subtract the shift start offset and get the 12 hour modulus which will get the number of milliseconds into the shift.
- Divide that by the number of ms in a minute (60,000) and you've got your minutes into shift.

> **[Expression Language and Syntax | Ignition User Manual](https://docs.inductiveautomation.com/docs/8.3/platform/expression-language-and-syntax)**
>
> Expression Language

You can think of expressions being like Excel's functions (which you would write into a cell formula) and scripts being like Excel Developer VBA code.  
Expressions take 0 or more inputs, perform an operation and output a result. You can't write a program in Expression Language.
