TimeNum() compared with seconds calculation

TimeClause = (TimeNum() > (now(4) - Interval() * TimeUnit));

I would like to set the above condition for the Explorer filter, because I want to display only the entries that met a certain time value, i.e., after 11:00 am Eastern Time, and not showing every entries including pre-market data, etc.

My issue is this expression sometimes returns incorrect results (although it returns correct results most of the time), for example, if TimeUnit = 8 and interval () is 5 minute, which is 5x60= 300, and 8x300=2400. So if the current time Now(4) is, say, 82100, then 82100 - 2400 = 79700, which is wrong, because there is no 97 minute in the clock. I tried:

TimeClause = (TimeNum() > DateTimeDiff(now(4), interval() * TimeUnit));

But can't get it to work. Any help would be greatly appreciated, thanks in advance.


DateTimeAdd() will correctly add / subtract the required intervals that you need.
Later if you dont need the date part of it, then you could just extract the time component and use it for your calculations.

with this one

Your usage of DateTimeDiff() is incorrect. Both arguments have to be of DateTime() type.
Same applies for the calculation you are trying to do with TimeNum(). Check the manual again if you want to do the math yourself.

DateTimeAdd( Now(5), -1 * TimeUnit, interval() );  // Negative to subtract
1 Like

If you are going to rush yourself, you will keep making these silly mistakes.
We just need to read the help manual.

You are converting to TimeNum() format and then passing it to DateTimeToStr().
It is obvious mismatch.
Just printf TimeNum() result.

Thanks, I got it figured out. Thank you!