Splunk Search

How to write a search to find stats for a specific time range based on the day of the week?

Kukkadapu
Path Finder

Hi,

How do I get the stats for the last week/month for different time frames based on the day of the week?

Monday to Saturday 10:00 AM - 9:00 PM
Sunday 12:00 PM - 8:00 PM

Thanks.

0 Karma
1 Solution

vasildavid
Path Finder

You should be able to do this with a 'where' clause and the date_wday/date_hour fields like this:

search sourcetype=bob | where (date_hour>=10 AND date_hour<21 AND date_wday!="sunday") OR (date_hour>=12 AND date_hour<20 AND date_wday=="sunday")

View solution in original post

0 Karma

somesoni2
Revered Legend

Try something like this

If date_hour and date_wday fields are available in your events

index=foo sourcetype=bar  (date_wday=sunday AND date_hour>=12 date_hour<20 ) OR (date_wday!=sunday AND date_hour>=10 date_hour<21 ) 

If they are not

 index=foo sourcetype=bar | eval date_wday=lower(strftime(_time,"%A")) | eval date_hour=tonumber(strftime(_time,"%H")) | where  (date_wday=sunday AND date_hour>=12 date_hour<20 ) OR (date_wday!=sunday AND date_hour>=10 date_hour<21 ) 

Kukkadapu
Path Finder

I've date_hour and date_wday fields. Thanks for your time.

0 Karma

vasildavid
Path Finder

You should be able to do this with a 'where' clause and the date_wday/date_hour fields like this:

search sourcetype=bob | where (date_hour>=10 AND date_hour<21 AND date_wday!="sunday") OR (date_hour>=12 AND date_hour<20 AND date_wday=="sunday")
0 Karma

Kukkadapu
Path Finder

Thanks that worked:)

0 Karma
Get Updates on the Splunk Community!

Updated Team Landing Page in Splunk Observability

We’re making some changes to the team landing page in Splunk Observability, based on your feedback. The ...

New! Splunk Observability Search Enhancements for Splunk APM Services/Traces and ...

Regardless of where you are in Splunk Observability, you can search for relevant APM targets including service ...

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...