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 Decoded: Service Maps vs Service Analyzer Tree View vs Flow Maps

It’s Monday morning, and your phone is buzzing with alert escalations – your customer-facing portal is running ...

What’s New in Splunk Observability – September 2025

What's NewWe are excited to announce the latest enhancements to Splunk Observability, designed to help ITOps ...

Fun with Regular Expression - multiples of nine

Fun with Regular Expression - multiples of nineThis challenge was first posted on Slack #regex channel ...