<?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: How to edit my search to exclude events outside of certain times of the day? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334272#M99337</link>
    <description>&lt;P&gt;Thanks.  Be sure to upvote somesoni2's answer as well, which was basically the same answer.&lt;/P&gt;

&lt;P&gt;Also, see woodcock's note about time values, which are notoriously squirrelly as soon as you have the temerity to crawl outside a single time zone...  &lt;/P&gt;

&lt;P&gt;(Your organization's mileage may vary, and it may be measured in kilometers or leagues.)&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2017 21:46:21 GMT</pubDate>
    <dc:creator>DalJeanis</dc:creator>
    <dc:date>2017-03-02T21:46:21Z</dc:date>
    <item>
      <title>How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334262#M99327</link>
      <description>&lt;P&gt;Greetings,&lt;/P&gt;

&lt;P&gt;I need to run a search and only pull certain events that happen between midnight and 5:00 AM.  So I use the date_time function in the following search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=[my index] sourcetype="[my source type]" [|inputlookup Admins.csv]| search date_hour&amp;gt;=0 date_hour&amp;lt;=5|rename _time AS Time |table Time, IP_ADDRESS, USER_ID, USER_NAME, SESSION_CREATE_TIME |sort USER_NAME, -SESSION_CREATE_TIME |convert timeformat="%a %b %d, %Y %I:%M:%S %p" ctime(Time) As Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The problem is it also includes events between 5:00 AM and 5:59 AM since it's looking at the hour.  I could change it so date_time&amp;lt;5 but then someone could log in exactly at 5:00 AM and avoid the report.  Is there a way around that (even if I could search for events between midnight and 5:01 AM)?  I realize it's extremely unlikely, but I'd like to make sure that it includes any "5:00 AM" events should they occur.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:10:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334262#M99327</guid>
      <dc:creator>SplunkLunk</dc:creator>
      <dc:date>2017-03-02T20:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334263#M99328</link>
      <description>&lt;P&gt;It might be sloppy, but one of my dashboards has hour-exclusion logic for this reason. &lt;/P&gt;

&lt;P&gt;The code that gets generated is something like this. date_hour didn't work for us on this one. &lt;/P&gt;

&lt;P&gt;Were doing just the oppistie of you.. We want to exclude from midnight to 6 AM. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;|eval hours=strftime(_time, "%H")
|where (NOT hours=0 AND NOT hours=1 AND NOT hours=2 AND NOT hours=3 AND NOT hours=4 AND NOT hours=5) 
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The dashboard code is such, if you care. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; &amp;lt;input type="multiselect" token="exclude"&amp;gt;
      &amp;lt;label&amp;gt;Exclue Hours&amp;lt;/label&amp;gt;
      &amp;lt;prefix&amp;gt;(NOT hours=25 AND &amp;lt;/prefix&amp;gt;
      &amp;lt;choice value="=25"&amp;gt;None&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=0"&amp;gt;12AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=1"&amp;gt;1AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=2"&amp;gt;2AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=3"&amp;gt;3AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=4"&amp;gt;4AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=5"&amp;gt;5AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=6"&amp;gt;6AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=7"&amp;gt;7AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=8"&amp;gt;8AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=9"&amp;gt;9AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=10"&amp;gt;10AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=11"&amp;gt;11AM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=12"&amp;gt;12PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=13"&amp;gt;1PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=14"&amp;gt;2PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=15"&amp;gt;3PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=16"&amp;gt;4PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=17"&amp;gt;5PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=18"&amp;gt;6PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=19"&amp;gt;7PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=20"&amp;gt;8PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=21"&amp;gt;9PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=22"&amp;gt;10PM&amp;lt;/choice&amp;gt;
      &amp;lt;choice value="=23"&amp;gt;11PM&amp;lt;/choice&amp;gt;
      &amp;lt;suffix&amp;gt;)&amp;lt;/suffix&amp;gt;
      &amp;lt;delimiter&amp;gt; AND &amp;lt;/delimiter&amp;gt;
      &amp;lt;valuePrefix&amp;gt;NOT hours&amp;lt;/valuePrefix&amp;gt;
      &amp;lt;default&amp;gt;=0,=1,=2,=3,=4,=23&amp;lt;/default&amp;gt;
    &amp;lt;/input&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:21:12 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334263#M99328</guid>
      <dc:creator>JDukeSplunk</dc:creator>
      <dc:date>2017-03-02T20:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334264#M99329</link>
      <description>&lt;P&gt;Try like this&lt;/P&gt;

&lt;P&gt;&lt;STRONG&gt;Updated&lt;/STRONG&gt; &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=[my index] sourcetype="[my source type]" [|inputlookup Admins.csv]| | search NOT ( (date_hour&amp;gt;=0 AND date_hour&amp;lt;5) OR (date_hour=5  date_minute=0) ) |rename _time AS Time |table Time, IP_ADDRESS, USER_ID, USER_NAME, SESSION_CREATE_TIME |sort USER_NAME, -SESSION_CREATE_TIME |convert timeformat="%a %b %d, %Y %I:%M:%S %p" ctime(Time) As Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you want to be more specific, include date_second as well.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=[my index] sourcetype="[my source type]" [|inputlookup Admins.csv]| | search NOT ( (date_hour&amp;gt;=0 AND date_hour&amp;lt;5) OR (date_hour=5  date_minute=0 date_second=0) )|rename _time AS Time |table Time, IP_ADDRESS, USER_ID, USER_NAME, SESSION_CREATE_TIME |sort USER_NAME, -SESSION_CREATE_TIME |convert timeformat="%a %b %d, %Y %I:%M:%S %p" ctime(Time) As Time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:40:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334264#M99329</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-03-02T20:40:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334265#M99330</link>
      <description>&lt;P&gt;Use two tests, one for before 5:00 AM and one for exactly 5:00 AM. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=[my index] sourcetype="[my source type]" [|inputlookup Admins.csv]
| search (date_hour&amp;lt;5) OR (date_hour=5 AND date_minute=0)
| rename _time AS Time 
| table Time, IP_ADDRESS, USER_ID, USER_NAME, SESSION_CREATE_TIME 
| sort 0 USER_NAME, -SESSION_CREATE_TIME 
| convert timeformat="%a %b %d, %Y %I:%M:%S %p" ctime(Time) As Time
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;HR /&gt;

&lt;P&gt;Notes - &lt;BR /&gt;
I've counted anything in that minute from 5:00:00 to 5:00:59 as a 5:00 AM logon.  You could add (...AND date_SECOND=0) if you prefer.&lt;/P&gt;

&lt;P&gt;I have added the qualifier 0 to your sort command to give you all results, just in case you receive more results than the default limit of 10000.&lt;/P&gt;

&lt;HR /&gt;

&lt;P&gt;You could also do this.  Basically, just format the time and then test again, but the above will be more efficient. &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search date_hour&amp;gt;=0 date_hour&amp;lt;=5|
| eval mytime=strftime(_time,"%H:%M:%S") | where mytime&amp;lt;="05:00:00"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 20:56:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334265#M99330</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-02T20:56:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334266#M99331</link>
      <description>&lt;P&gt;I think this will work.  I have no sure fire way to test it unless I somehow try to have someone log in exactly at 5:00 AM.  However, if I read your solution correctly it's saying not to exclude anything 5:00 AM or less even though it would have a hour of "5".  That should be work.  Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:00:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334266#M99331</guid>
      <dc:creator>SplunkLunk</dc:creator>
      <dc:date>2017-03-02T21:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334267#M99332</link>
      <description>&lt;P&gt;I believe the "NOT (date_hour=5 AND date_minute=0)" is the reverse of the desired effect.  The two conditions before it should be in parenthesis, and the NOT should be OR. &lt;/P&gt;

&lt;P&gt;I believe the  date_hour&amp;gt;=0 is superfluous as well, since it will never be negative, and can be eliminated.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:03:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334267#M99332</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2020-09-29T13:03:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334268#M99333</link>
      <description>&lt;P&gt;First of all, DO NOT use the "free" &lt;CODE&gt;date_*&lt;/CODE&gt; values because they are PRE-TZ-normalization artifacts and are (almost) always wrong.  Instead, calculate your own like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=[my index] sourcetype="[my source type]" [|inputlookup Admins.csv]
| eval date_hourmin=strftime(_time, "%H%M")
| search date_hourmin&amp;lt;=500
| rename _time AS Time
| table Time, IP_ADDRESS, USER_ID, USER_NAME, SESSION_CREATE_TIME
| sort USER_NAME, -SESSION_CREATE_TIME
| convert timeformat="%a %b %d, %Y %I:%M:%S %p" ctime(Time) As Time
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:12:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334268#M99333</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-02T21:12:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334269#M99334</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/203121"&gt;@DalJeanis&lt;/a&gt; for catching that. Updated the condition. FOr anyone want to test date_hour and date_minute values will be returned, can try this runanywhere search&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 | eval date_hour=mvrange(0,24) | table date_hour | mvexpand date_hour | eval date_minute=mvrange(0,60)  | mvexpand date_minute | search NOT ( (date_hour&amp;gt;=0 AND date_hour&amp;lt;5) OR (date_hour=5  date_minute=0) )
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:03:41 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334269#M99334</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2020-09-29T13:03:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334270#M99335</link>
      <description>&lt;P&gt;Winner, Winner, Chicken Dinner!  My revised query looks like:&lt;/P&gt;

&lt;P&gt;index=[my index]  sourcetype="[my source]" [|inputlookup Admins.csv]&lt;BR /&gt;
|search (date_hour&amp;gt;=0 AND date_hour&amp;lt;5) OR (date_hour=5  date_minute=0)  |rename _time AS Time |table Time, IP_ADDRESS, USER_ID, USER_NAME, SESSION_CREATE_TIME |sort -SESSION_CREATE_TIME |convert timeformat="%a %b %d, %Y %I:%M:%S %p" ctime(Time) As Time&lt;/P&gt;

&lt;P&gt;I tested it out by expanding the search through 8:00 AM and got lots of results during the 8:00 AM hour.  Picked one event at 8:26 AM and added the OR (date_hour=8  date_minute=26) and confirmed the 8:26 AM event showed in the results and none of the other events during the 8:00 hour showed up.  So this tells me the above query will show all events from between midnight and 5:00 AM exactly.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:05:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334270#M99335</guid>
      <dc:creator>SplunkLunk</dc:creator>
      <dc:date>2020-09-29T13:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334271#M99336</link>
      <description>&lt;P&gt;Winner, Winner, Chicken Dinner! My revised query looks like:&lt;/P&gt;

&lt;P&gt;index=[my index] sourcetype="[my source]" [|inputlookup Admins.csv]&lt;BR /&gt;
|search (date_hour&amp;gt;=0 AND date_hour&amp;lt;5) OR (date_hour=5 date_minute=0) |rename _time AS Time &lt;BR /&gt;
|table Time, IP_ADDRESS, USER_ID, USER_NAME, SESSION_CREATE_TIME |sort -SESSION_CREATE_TIME |convert timeformat="%a %b %d, %Y %I:%M:%S %p" ctime(Time) As Time&lt;/P&gt;

&lt;P&gt;I tested it out by expanding the search through 8:00 AM and got lots of results during the 8:00 AM hour. Picked one event at 8:26 AM and added the OR (date_hour=8 date_minute=26) and confirmed the 8:26 AM event showed in the results and none of the other events during the 8:00 hour showed up. So this tells me the above query will show all events from between midnight and 5:00 AM exactly.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 13:05:50 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334271#M99336</guid>
      <dc:creator>SplunkLunk</dc:creator>
      <dc:date>2020-09-29T13:05:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334272#M99337</link>
      <description>&lt;P&gt;Thanks.  Be sure to upvote somesoni2's answer as well, which was basically the same answer.&lt;/P&gt;

&lt;P&gt;Also, see woodcock's note about time values, which are notoriously squirrelly as soon as you have the temerity to crawl outside a single time zone...  &lt;/P&gt;

&lt;P&gt;(Your organization's mileage may vary, and it may be measured in kilometers or leagues.)&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:46:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334272#M99337</guid>
      <dc:creator>DalJeanis</dc:creator>
      <dc:date>2017-03-02T21:46:21Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334273#M99338</link>
      <description>&lt;P&gt;Please take a look at my answer; you are in danger of bad conclusions!&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 21:48:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334273#M99338</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-02T21:48:15Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334274#M99339</link>
      <description>&lt;P&gt;Thanks.  I've revised my search based on your comments.  It's pulls up the same results as the previous search but if I may run into time zone issues then I'll stick with this one.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 13:42:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334274#M99339</guid>
      <dc:creator>SplunkLunk</dc:creator>
      <dc:date>2017-03-09T13:42:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to edit my search to exclude events outside of certain times of the day?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334275#M99340</link>
      <description>&lt;P&gt;Plus, there are many inputs that do not have the `date_* fields.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2017 14:51:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-edit-my-search-to-exclude-events-outside-of-certain-times/m-p/334275#M99340</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-03-09T14:51:32Z</dc:date>
    </item>
  </channel>
</rss>

