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!

Splunk Observability as Code: From Zero to Dashboard

For the details on what Self-Service Observability and Observability as Code is, we have some awesome content ...

[Puzzles] Solve, Learn, Repeat: Character substitutions with Regular Expressions

This challenge was first posted on Slack #puzzles channelFor BORE at .conf23, we had a puzzle question which ...

Shape the Future of Splunk: Join the Product Research Lab!

Join the Splunk Product Research Lab and connect with us in the Slack channel #product-research-lab to get ...