I’m using timeBetween
with full date objects and from what I’ve tested with manual values, even if the dates don’t match up, as long as the time is within the range, it should work. However, I’m getting all three values for the timeBetween
expression function from tags, and their values are:
date = Fri May 10 10:00:00 CDT 2019
startDate = Mon Jul 15 07:00:00 CDT 2019
endDate = Mon Jul 15 19:00:00 CDT 2019
(values copied from the tag browser)
However, with these tags, timeBetween
is returning false. Is this a bug?
EDIT: Whenever I set date
to have the same date as the start/end dates, it works. But shouldn’t timeBetween
only be comparing the times, not the date values?
Hmm. Neither the docs nor the function implementation suggests that the Y/M/D portion of a date will be ignored.
and its implementation hasn’t changed meaningfully in years.
1 Like
So that means there’s no meaningful difference between timeBetween
and dateIsBetween
? Except I guess that timeBetween
will work without a date component present?
Yes, timeBetween
works when the Y/M/D is not specified by setting those components to Jan 1, 1970 and then doing the comparison as normal.
1 Like
Ah okay, I see. Apologies for misunderstanding things.
I’ve made this work by using dateFormat
to format all the parameters to the timeBetween
function as hh:mm:ss a
format, so just throwing out the date portion effectively.
Thanks for the clarification!
1 Like
Just to add a little footnote here, my goal with this was to check if a time falls within a “shift”, and that includes shifts where the start time is AFTER the end time (i.e: night shift, goes from 7PM to 7AM)
Checking this in the expression language takes a bit of trickery, but it’s not terrible. Basically the expression I wrote checks if the start time is after the end time, and if it is, compares by swapping the start/end times in the timeBetween
function and subtracting off 12 hours from the current time/time being checked. This works with time/date items, since it throws away any date portion of the time. (This just kind of assumes that {StartDate}
and {EndDate}
don’t have mismatching date components that would cause this checking to fail)
Here’s the function for anyone who might find it useful:
if(dateIsAfter({StartDate}, {EndDate}),
timeBetween(
dateFormat(addHours({CurrentDate}, -12), "hh:mm:ss a"),
dateFormat({EndDate}, "hh:mm:ss a"),
dateFormat({StartDate}, "hh:mm:ss a")),
timeBetween(
dateFormat({CurrentDate}, "hh:mm:ss a"),
dateFormat({StartDate}, "hh:mm:ss a"),
dateFormat({EndDate}, "hh:mm:ss a")))
Hi,
we Have Done with the 3shift timings. but working with the 3shifr exactly but getting the point
Exactly In shift2 whenever it goes to the Next day starting time at the 00:00 Shift2 is not getting enable.
as this above-mentioned image working only for the shift 1 & 3 not for the shift 2. so what might the Issue.How we can resolve it