# Finding what the current work Shift is and when it started, 4x 12 hour shifts

**URL:** <https://forum.inductiveautomation.com/t/finding-what-the-current-work-shift-is-and-when-it-started-4x-12-hour-shifts/76458>\
**Category:** Ignition\
**Tags:** ignition80\
**Created:** [July 17, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/finding-what-the-current-work-shift-is-and-when-it-started-4x-12-hour-shifts/76458 "2023-07-17T14:42:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Seth\_Feuerborn](https://avatars.discourse-cdn.com/v4/letter/s/85e7bf/32.png) [@Seth\_Feuerborn](https://forum.inductiveautomation.com/u/Seth_Feuerborn)\
**Post date:** [July 17, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/finding-what-the-current-work-shift-is-and-when-it-started-4x-12-hour-shifts/76458/1 "2023-07-17T14:42:03Z")

</div>

We are migrating the facility rounds (clip board and paper) to tablets with an Ignition HMI. Being that I am new to Ignition expression scripting, this post is a solicitation for feedback. Below are the methods I used to find what shift it currently is using the workweek even/odd cycle and the start time of current shift. These are expression tags referenced in other expressions, mainly the numeric input template to set background color to indicate its been looked at.

**Shift Expression**

if(  
toBoolean(dateExtract(now(0), 'week') % 2 \> 0),  
//AD Long, evaluate time  
if(timeBetween(now(), "7:00:00 am", "7:00:00 pm"),  
if(toint(getDayofweek(now()))\<5,"A","C"),  
if(toint(getDayofweek(now()))\>3,"D","B")),  
if(timeBetween(now(), "7:00:00 am", "7:00:00 pm"),  
if(toint(getDayofweek(now()))\<4,"A","C"),  
if(toint(getDayofweek(now()))=4|5|6,"D","B"))  
)

**Start of current shift expression**

//start with seeing if its after 7pm,  
//true=set start time to current day at 19:00  
//false = if statement to see if less than 7am.  
//true = set start time to 19:00 of the prior day  
//false = set start time to 7:00 of current day.  
if(gethour24(now())\>19,  
settime(getDate(getYear(now(0)),getMonth(now(0)),toint(getDayOfMonth(now(0)))),19,0,0),  
if(gethour24(now())\<7,  
settime(getDate(getYear(now(0)),getMonth(now(0)),toint(getDayOfMonth(now(0))-1)),19,0,0),  
settime(getDate(getYear(now(0)),getMonth(now(0)),toint(getDayOfMonth(now(0)))),7,0,0)  
)  
)

---

<div class="post-metadata">

**Author:** ![zacht](https://avatars.discourse-cdn.com/v4/letter/z/ea5d25/32.png) [@zacht](https://forum.inductiveautomation.com/u/zacht)\
**Post date:** [July 17, 2023, 2:53pm UTC](https://forum.inductiveautomation.com/t/finding-what-the-current-work-shift-is-and-when-it-started-4x-12-hour-shifts/76458/2 "2023-07-17T14:53:26Z")

</div>

This may be overkill for what you need, but I'm a big fan of the system that @pturmel shared in this post:

> [@Script for periodically changing shift time](https://forum.inductiveautomation.com/t/script-for-periodically-changing-shift-time/51058/3):
>
> Hi Berkay, I like to solve this kind of problem with a smart database, like PostgreSQL, where I can define a pattern and repeat it with table generating functions. I tweaked one of my implementations to serve as an example: create table shift\_schedules (shift\_id serial, shift\_name varchar(255), refdate date, repeat int, tzname varchar(255), primary key (shift\_id)); insert into shift\_schedules (shift\_name, refdate, repeat, tzname) values ('Berkay Cinar 3wk', '2021-07-26', 21, 'America/Ne…
