If with timeBetween

Hi

I want to get the time and return a value in an expression but don´t work can you help me?

the format of the tags are “MM-dd-yyyy hh:mm:ss”

i have this

if (timeBetween(dateFormat(now(), “MM:dd:aa hh:mm”), {[.]StartTime_Shift1}, {[.]StartTime_Shift2}),1,2)

this sends me “error configuration”

tried with this too

if (timeBetween(now(), {[.]StartTime_Shift1}, {[.]StartTime_Shift2}),1,2)
but always sends me 2.

can you explain why don´t work?

regards

If you are using 24-hour time format, use 'HH' instead. Otherwise, you need the meridiam (am/pm).

This is not a valid date. 'aa' should probably be 'dd'.


For shift times, I use a few string tags to hold just the time.
[default]ShfitTimes/Shift1: 6:00 am
[default]ShfitTimes/Shift2: 2:00 pm

if(timeBetween(dateFormat(now(),"h:mm:ss a"), 
               {[default]ShfitTimes/Shift1}, 
               {[default]ShfitTimes/Shift2}
               ),
    1,
    2
   )

Thanks Jordan

last question how did you make your tags with this values?

i use a tag startime_shift1 type string concat two tags type integer i think this make the problem when i try to use the between

Mine are currently looked up from a dataset, because different lines have different start times and break times, or are 2-shift vs 3 shift operations.

But when I first started, it was just an string expression tag with the value “6:00 am”. Memory tags didn’t exist in the old days. :wink:

Thanks, i resolved my problem.

regards

Jordan,
I am using dateArithmetic(now(), -60, “minute” for last 60 for tag ScaleNow1hr, but when the second shift starts at 2pm, there is a spillover. Where do i put your code in to pull sql data in a tag?

if(timeBetween(dateFormat(now(),“h:mm:ss”),
{[default]ShfitTimes/Shift1},
{[default]ShfitTimes/Shift2}
),
1,
2
)
:mycode for last 60min
SELECT sum(actual) as ‘sum’ FROM mydatabase
WHERE
T_stamp >= ‘{[.]ScaleMinus1hr}’ and T_Stamp < ‘{[.]ScaleNow}’

Hi Jay, sorry for the late reply.

Been on vacation the past few days, and today is more of a family day :wink: .

The expressions I posted above isn’t the best fit for what you’re needing, but I can post something tomorrow morning. Probably be a couple more expressions to handle the demarcation of shifts.

Shh, my wife is coming. Later!

Okay, this one is a bit more involved. I switched this to seconds, as the seconds portion of the date still fluctuated when using minutes.

ScaleMinus1hr (uses the smaller absolute value between start-of-shift to now or 3600 seconds):

addSeconds(now(),
		   max(case({[.]Current Shift},
		 	  		1, secondsBetween(toDate(dateFormat(now(), 'hh:mm:ss a')), toDate({[.]Shift1})),
	 	 	   		2, secondsBetween(toDate(dateFormat(now(), 'hh:mm:ss a')), toDate({[.]Shift2})),
	 	 	   		0
	 		  	   ),
	 		   -3600
	 		  )
		   )

Query (Note that you don’t need to specify less than now, as there will be no data that exists above now, How’s that for existential?):

SELECT sum(actual) as ‘sum’ FROM mydatabase
WHERE
T_stamp >= ‘{[.]ScaleMinus1hr}’

Hope this helps!

1 Like