Dashboards & Visualizations

How do you insert a time range inside a query?

zacksoft
Contributor

I am trying to define my search range inside a query by using the earliest / latest parameter or something similar. But, I am getting a syntax error. I tried a few different techniques.

The condition is...
"I want to count the number of events generated between 10 AM to 2 PM everyday for last 50 days"

0 Karma
1 Solution

kamlesh_vaghela
SplunkTrust
SplunkTrust

@zacksoft

Can you please try this?

YOUR_SEARCH
 | eval date_hour=strftime(_time, "%H") 
 | search date_hour>=10 date_hour<=14 | stats count

Adding minute filter

YOUR_SEARCH
    | eval date_hour=strftime(_time, "%H"), date_min=strftime(_time, "%M") 
    | search date_hour>10 date_hour<14 OR (date_hour=10 date_min>=30) OR (date_hour=14 date_min<=45)  | stats count

Thanks

View solution in original post

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@zacksoft

Can you please try this?

YOUR_SEARCH
 | eval date_hour=strftime(_time, "%H") 
 | search date_hour>=10 date_hour<=14 | stats count

Adding minute filter

YOUR_SEARCH
    | eval date_hour=strftime(_time, "%H"), date_min=strftime(_time, "%M") 
    | search date_hour>10 date_hour<14 OR (date_hour=10 date_min>=30) OR (date_hour=14 date_min<=45)  | stats count

Thanks

0 Karma

zacksoft
Contributor

Thanks,
What if I want to make it between 10:45 AM to 02:30 PM ?
How do I add the minute field ?

0 Karma

kamlesh_vaghela
SplunkTrust
SplunkTrust

@zacksoft

I have updated my Answer. Can you please check it?

0 Karma
Get Updates on the Splunk Community!

Building Reliable Asset and Identity Frameworks in Splunk ES

 Accurate asset and identity resolution is the backbone of security operations. Without it, alerts are ...

Cloud Monitoring Console - Unlocking Greater Visibility in SVC Usage Reporting

For Splunk Cloud customers, understanding and optimizing Splunk Virtual Compute (SVC) usage and resource ...

Automatic Discovery Part 3: Practical Use Cases

If you’ve enabled Automatic Discovery in your install of the Splunk Distribution of the OpenTelemetry ...