Splunk Search

Comparing hours and minutes TOGETHER

asarolkar
Builder

I am trying to get records in a certain time range (11:45 AM and 1:45 PM) and I can only rely on date_ hour and date_ minute to be my anchors of division

This search that I came up with is extremely inefficient (and does not work)

sourcetype="syslog" | ... | eval range=case((date_hour>=11 AND date_minute>=45) AND (date_hour<=13  AND date_minute<=45)), "in", ( (date_hour<=11 AND date_minute<=45) OR  (date_hour>13 AND date_minute>45)), "out" )

Any body know of a more useful alternative ?
What if I want to add a date_ month comparison in there as well ?

1 Solution

yannK
Splunk Employee
Splunk Employee

Do a simple conversion of the time in minutes (time = hour*60 + minute) and setup a condition

... | eval minute_of_the_day = date_hour*60+date_minute
| eval range=if(minute_of_the_day<(11*60+45),"out",if(minute_of_the_day<=(13*60+45),"in","out"))

View solution in original post

yannK
Splunk Employee
Splunk Employee

Do a simple conversion of the time in minutes (time = hour*60 + minute) and setup a condition

... | eval minute_of_the_day = date_hour*60+date_minute
| eval range=if(minute_of_the_day<(11*60+45),"out",if(minute_of_the_day<=(13*60+45),"in","out"))

Get Updates on the Splunk Community!

Observe and Secure All Apps with Splunk

  Join Us for Our Next Tech Talk: Observe and Secure All Apps with SplunkAs organizations continue to innovate ...

Splunk Decoded: Business Transactions vs Business IQ

It’s the morning of Black Friday, and your e-commerce site is handling 10x normal traffic. Orders are flowing, ...

Fastest way to demo Observability

I’ve been having a lot of fun learning about Kubernetes and Observability. I set myself an interesting ...