<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Search to only include Business Hours and Exclude weekends in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69665#M17456</link>
    <description>&lt;P&gt;Hi &lt;/P&gt;

&lt;P&gt;Thanks, this worked like a charm. I started to try different methods and it would seem the below is slightly faster is there a reason for this ?&lt;/P&gt;

&lt;P&gt;date_wday!="saturday" AND date_wday!="sunday" &lt;BR /&gt;
| eval myHour=strftime(_time, "%H") &lt;BR /&gt;
| eval myMinute=strftime(_time, "%M") &lt;BR /&gt;
| where ( (myHour &amp;lt;= 18 AND myMinute &amp;gt;= 00) AND (myHour &amp;gt; 5 AND myMinute &amp;lt;= 59) )&lt;/P&gt;</description>
    <pubDate>Mon, 28 Sep 2020 12:59:53 GMT</pubDate>
    <dc:creator>wellsajs</dc:creator>
    <dc:date>2020-09-28T12:59:53Z</dc:date>
    <item>
      <title>Search to only include Business Hours and Exclude weekends</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69661#M17452</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;

&lt;P&gt;I am trying to generate a search that only includes Business hours and also excludes weekends.&lt;BR /&gt;
I have tried any combinations and still cannot get it working.&lt;/P&gt;

&lt;P&gt;I have tried the below which I thought would work but it did not give me the results I wanted&lt;/P&gt;

&lt;P&gt;((date_hour&amp;lt;=18 AND date_hour&amp;gt;=6) OR (date_wday!="sunday" AND date_wday!="saturday"))&lt;/P&gt;

&lt;P&gt;Cheers for any help&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:59:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69661#M17452</guid>
      <dc:creator>wellsajs</dc:creator>
      <dc:date>2020-09-28T12:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Search to only include Business Hours and Exclude weekends</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69662#M17453</link>
      <description>&lt;P&gt;The best way to create your search strings is step by step.&lt;BR /&gt;
in the search string the AND is always implied unless you say something different, so no need for that. &lt;/P&gt;

&lt;P&gt;Try this first without any date_hour restriction:&lt;BR /&gt;
date_wday!="sunday" date_wday!="saturday"&lt;/P&gt;

&lt;P&gt;You will see it will work because you are telling Splunk to search all the fields but the ones that have the value Sunday or Saturday&lt;/P&gt;

&lt;P&gt;For the time restriction, I'd recommend you used the eval function. &lt;A href="http://docs.splunk.com/Documentation/Splunk/5.0/searchreference/eval" target="_blank"&gt;http://docs.splunk.com/Documentation/Splunk/5.0/searchreference/eval&lt;/A&gt;&lt;/P&gt;

&lt;P&gt;anyhow, you can always have this working&lt;/P&gt;

&lt;P&gt;date_hour&amp;gt;=6 date_hour&amp;lt;=18 date_wday!="sunday" date_wday!="saturday"&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:59:47 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69662#M17453</guid>
      <dc:creator>GKC</dc:creator>
      <dc:date>2020-09-28T12:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: Search to only include Business Hours and Exclude weekends</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69663#M17454</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;

&lt;P&gt;When I run the below&lt;/P&gt;

&lt;P&gt;date_hour&amp;gt;=6 date_hour&amp;lt;=18 date_wday!="sunday" date_wday!="saturday"&lt;/P&gt;

&lt;P&gt;I get nothing as Splunk tells me "No matching events found" my timepicker is the last 7 days and with out this filter i get thousands of events over each of the last 7 days.&lt;/P&gt;

&lt;P&gt;So not sure why that is not working&lt;/P&gt;

&lt;P&gt;Cheers&lt;BR /&gt;
J&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:59:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69663#M17454</guid>
      <dc:creator>wellsajs</dc:creator>
      <dc:date>2020-09-28T12:59:50Z</dc:date>
    </item>
    <item>
      <title>Re: Search to only include Business Hours and Exclude weekends</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69664#M17455</link>
      <description>&lt;P&gt;Not all events have &lt;CODE&gt;date_*&lt;/CODE&gt; fields. But all events have a timestamp.  So I would do it this way&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| eval hour = tonumber(strftime(_time,"%H"))
| eval dow = tonumber(strftime(_time,"%w"))
| where hour&amp;gt;=6 AND hour&amp;lt;=18 AND dow!=0 AND dow!=6
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If this doesn't seem to be working, try this as a debugging step&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;yoursearchhere
| eval hour = tonumber(strftime(_time,"%H"))
| eval dow = tonumber(strftime(_time,"%w"))
| eval timestamp = strftime(_time,"%x %X")
| table timestamp dow hour
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Dec 2012 05:04:00 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69664#M17455</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-20T05:04:00Z</dc:date>
    </item>
    <item>
      <title>Re: Search to only include Business Hours and Exclude weekends</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69665#M17456</link>
      <description>&lt;P&gt;Hi &lt;/P&gt;

&lt;P&gt;Thanks, this worked like a charm. I started to try different methods and it would seem the below is slightly faster is there a reason for this ?&lt;/P&gt;

&lt;P&gt;date_wday!="saturday" AND date_wday!="sunday" &lt;BR /&gt;
| eval myHour=strftime(_time, "%H") &lt;BR /&gt;
| eval myMinute=strftime(_time, "%M") &lt;BR /&gt;
| where ( (myHour &amp;lt;= 18 AND myMinute &amp;gt;= 00) AND (myHour &amp;gt; 5 AND myMinute &amp;lt;= 59) )&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 12:59:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69665#M17456</guid>
      <dc:creator>wellsajs</dc:creator>
      <dc:date>2020-09-28T12:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Search to only include Business Hours and Exclude weekends</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69666#M17457</link>
      <description>&lt;P&gt;When there &lt;EM&gt;is&lt;/EM&gt; a &lt;CODE&gt;date_wday&lt;/CODE&gt; field in the events, it probably is faster to filter the events in the initial search.  It's a rule of thumb: "the earlier in the search pipeline that you can filter out events, the faster the search will run"&lt;/P&gt;

&lt;P&gt;BTW, you can completely drop the &lt;CODE&gt;myMinute&lt;/CODE&gt; field and the related tests from your search - it will work just the same and run even faster&lt;/P&gt;

&lt;P&gt;&lt;CODE&gt;date_wday!="saturday" AND date_wday!="sunday" &lt;BR /&gt;
| eval myHour=strftime(_time, "%H") &lt;BR /&gt;
| where ( myHour &amp;lt;= 18 AND myHour &amp;gt; 5 )&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2012 06:25:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69666#M17457</guid>
      <dc:creator>lguinn2</dc:creator>
      <dc:date>2012-12-20T06:25:36Z</dc:date>
    </item>
    <item>
      <title>Re: Search to only include Business Hours and Exclude weekends</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69667#M17458</link>
      <description>&lt;P&gt;Thanks very much for taken the time to explain things and provide a solution, much appreciated&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2012 06:53:11 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69667#M17458</guid>
      <dc:creator>wellsajs</dc:creator>
      <dc:date>2012-12-20T06:53:11Z</dc:date>
    </item>
    <item>
      <title>Re: Search to only include Business Hours and Exclude weekends</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69668#M17459</link>
      <description>&lt;P&gt;Thank you @lguinn. &lt;/P&gt;</description>
      <pubDate>Sat, 24 Sep 2016 10:43:52 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Search-to-only-include-Business-Hours-and-Exclude-weekends/m-p/69668#M17459</guid>
      <dc:creator>saurabh_tek</dc:creator>
      <dc:date>2016-09-24T10:43:52Z</dc:date>
    </item>
  </channel>
</rss>

