Our full technical support staff does not monitor this forum. If you need assistance from a member of our staff, please submit your question from the Ask a Question page.


Log in or register to post/reply in the forum.

TimeintoInterval Help


Zpoole Aug 17, 2020 04:30 PM

Looking for a way around using portinterval to set C1 off on a CR300 during weekends. My current code i've tested is as follows:

if TimeIntoInterval(480,1440,min) then
PortSet(C1,1)
elseif TimeIntoInterval(1200,1440,min) then
PortSet(C1,0)
elseif TimeIntoInterval (5,7,Day) or TimeIntoInterval (6,7,Day) then
Portset(C1,0)
endif

I turn the port on every morning and off at night. I was hoping for weekends to have it turned off, but this code just gets overwritten during Saturdays and Sundays.

Any suggestions?


JDavis Aug 17, 2020 06:36 PM

You can nest an if statement inside another if statement. Or, you can AND conditions together.  I prefer the newer TimeIsBetween instruction as well versus TimeIntoInterval. TimeIsBetween looks to see if you are within a time range, instead of one particular time.

I would approach it as checking to see if you are within the range of days, and the range of time you want to be on.

 

    If TimeIsBetween (2,6,7,Day) AND TimeIsBetween (480,1200,1440,min)  Then
      PortSet(C1,1)
    Else
      PortSet(C1,0)
    EndIf

 


Zpoole Aug 17, 2020 06:53 PM

Great, Thanks!

Log in or register to post/reply in the forum.