Comparing dates in script

I don’t know what is wrong in my code

The last line doesn’t run.
Not sure if the if statements aren’t ending or what is going on

    today = system.date.now()
	dayBefore = system.date.addDays(today, -1)
	shift3yesterday = system.date.setTime(dayBefore, 23, 0, 0)
	shift1today = system.date.setTime(today, 7, 0, 0)		
	shift2today = system.date.setTime(today, 15, 0, 0)		
	shift3today = system.date.setTime(today, 23, 0, 0)	
	
	
	if system.date.isbefore(today,shift1today) :
		currentshiftstart=shift3yesterday
		
		
	if system.date.isbetweeen(today,shift1today,shift2today) :
		currentshiftstart=shift1today
		
	if system.date.isbetween(today,shift2today,shift3today):
		currentshiftstart=shift2today
	
	if system.date.isafter(today,shift3today) :
		currentshiftstart=shift3today
		
	system.tag.writeBlocking(["[.]Current Shift Start"], [today])

system.date.isBefore
system.date.isBetween
system.date.isAfter

These are case sensitive; you’re missing a capital in the middle of each function name.

I would expect an error like AttributeError: 'com.inductiveautomation.ignition.designer.gui.tool' object has no attribute 'isbefore' in the gateway log.

What are you trying to do with currentshiftstart? It doesn’t appear that you’re calling it.

initially I marked it as the solution

would that make the bottom line not run?

Yes. It stops in line 9. I pasted your code into the Script Console to test.

how do I get to use that

Tools -> Script Console

image

Thanks so much

1 Like