IsBetweenDates - Bug? Or my understanding?

Hi, I’m having trouble with the IsBetweenDates function when writing an expression. My understanding is I should be able to provide it with two dates (inc. time) and if the current time is between those two, it will return true, else false. However, if I enter the following expression, it is evaluating to true:

isBetweenDates( addHours(now(),-8), addHours(now(),-10))

Now this should not be true, as the current time cannot be between 8 hours ago and 10 hours ago! If I change the addHours to addDays, I get false. This leads me to think perhaps the function is limited to just the date, and doesn’t look at the time?

Any advice?

That’s right. isBetweenDates() is a convenience method for comparing calendar dates.

Normally, if you want to compare two points in time (date + time), you would just compare those directly:

now() > addHours(now(), -10) and now() < addHours(now(), -8)

These simple comparisons get a bit more complicated when you are trying to compare between two calendar dates as there’s some manipulations needed. Without getting into all the details of it, you have to do a bunch of manipulations like resetting the year component, shifting the time on the ‘end’ date to the time at the end of the day, shifting years back and forth if it’s a cross-year comparison, etc.

So we built the isBetweenDates() as a bit of ‘syntactic sugar’ to make it easier to just compare those calendar dates directly without the overhead of having to rebuild all that logic.

For points in time, you can just use the comparison operators directly as shown above, so the special method isn’t needed.

1 Like

Ok thanks for the clarification