<?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 If statement for earliest time in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313197#M93755</link>
    <description>&lt;P&gt;I have a search that needs to either snap to 7am ( &lt;CODE&gt;-7h@d+7h&lt;/CODE&gt;) or 7pm ( &lt;CODE&gt;-7h@d+19h&lt;/CODE&gt;) depending on whether the time of search ( &lt;CODE&gt;now()&lt;/CODE&gt;) is between 7am-7pm or 7pm-7am. For example, if it is 8:30am, I need to see my search using &lt;CODE&gt;earliest=-7h@d+7h&lt;/CODE&gt;, but if it is 21:15, I need see my search using  &lt;CODE&gt;earliest=-7h@d+19h&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;I tried the following if statement, but it doesn't work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=if(now()&amp;gt;="-7h@d+7h" AND now()&amp;lt;"-7h@d+19h", "-7h@d+7h", "-7h@d+19h")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is for an embedded report, so I wasn't thinking I could use any XML or tokens.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 05 Apr 2017 21:31:01 GMT</pubDate>
    <dc:creator>mstark31</dc:creator>
    <dc:date>2017-04-05T21:31:01Z</dc:date>
    <item>
      <title>If statement for earliest time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313197#M93755</link>
      <description>&lt;P&gt;I have a search that needs to either snap to 7am ( &lt;CODE&gt;-7h@d+7h&lt;/CODE&gt;) or 7pm ( &lt;CODE&gt;-7h@d+19h&lt;/CODE&gt;) depending on whether the time of search ( &lt;CODE&gt;now()&lt;/CODE&gt;) is between 7am-7pm or 7pm-7am. For example, if it is 8:30am, I need to see my search using &lt;CODE&gt;earliest=-7h@d+7h&lt;/CODE&gt;, but if it is 21:15, I need see my search using  &lt;CODE&gt;earliest=-7h@d+19h&lt;/CODE&gt;. &lt;/P&gt;

&lt;P&gt;I tried the following if statement, but it doesn't work.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;earliest=if(now()&amp;gt;="-7h@d+7h" AND now()&amp;lt;"-7h@d+19h", "-7h@d+7h", "-7h@d+19h")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;This is for an embedded report, so I wasn't thinking I could use any XML or tokens.&lt;/P&gt;

&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 21:31:01 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313197#M93755</guid>
      <dc:creator>mstark31</dc:creator>
      <dc:date>2017-04-05T21:31:01Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for earliest time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313198#M93756</link>
      <description>&lt;P&gt;To handle that in search itself, you need to override earliest using subsearch, like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;your base search [| gentimes start=-1 | eval earliest=if(now()&amp;lt;=relative_time(now(),"-7h@d+7h") AND now()&amp;gt;=relative_time(now(),"-7h@d+19h"),"-7h@d+7h", "-7h@d+19h") | table earliest ] ...| rest of the search
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've used the relative time modifier from your question, so check if that's giving you correct values.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Apr 2017 21:39:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313198#M93756</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2017-04-05T21:39:31Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for earliest time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313199#M93757</link>
      <description>&lt;P&gt;Like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| makeresults
| eval earliest=if(now()&amp;lt;=relative_time(now(),"-7h@d+7h") AND now()&amp;gt;=relative_time(now(),"-7h@d+19h"),"-7h@d+7h", "-7h@d+19h")
| map search="search earliest=$earliest Your Search Here"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Apr 2017 03:17:29 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313199#M93757</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-06T03:17:29Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for earliest time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313200#M93758</link>
      <description>&lt;P&gt;Some minor typos, but otherwise this works. Thank you!&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; | makeresults
 | eval earliest=if(now()&amp;gt;=relative_time(now(),"-7h@d+7h") AND now()&amp;lt;relative_time(now(),"-7h@d+19h"),"-7h@d+7h", "-7h@d+19h")
 | map search="search earliest=$earliest$ Your Search Here"
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 06 Apr 2017 13:54:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313200#M93758</guid>
      <dc:creator>mstark31</dc:creator>
      <dc:date>2017-04-06T13:54:21Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for earliest time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313201#M93759</link>
      <description>&lt;P&gt;Bonus question - how do I escape quotes without using XML (this code is going in a macro)?&lt;/P&gt;

&lt;P&gt;My &lt;CODE&gt;map search&lt;/CODE&gt; pipe needs to look like this: &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| map search = "search earliest=$earliest$ index=my_index Process="Thing &amp;amp; Thing" Parameter=my_parameter"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I've determined that the quotes around &lt;CODE&gt;"Thing &amp;amp; Thing"&lt;/CODE&gt; are messing up the search string.&lt;/P&gt;

&lt;P&gt;My workaround is to add another line below &lt;CODE&gt;map search&lt;/CODE&gt; with &lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| search Process="Thing &amp;amp; Thing"
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;but this seems really kludgy.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 13:27:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313201#M93759</guid>
      <dc:creator>mstark31</dc:creator>
      <dc:date>2017-04-18T13:27:33Z</dc:date>
    </item>
    <item>
      <title>Re: If statement for earliest time</title>
      <link>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313202#M93760</link>
      <description>&lt;P&gt;You can escape by using &lt;CODE&gt;... \"Thing &amp;amp; Thing\" ...&lt;/CODE&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Apr 2017 13:47:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/If-statement-for-earliest-time/m-p/313202#M93760</guid>
      <dc:creator>woodcock</dc:creator>
      <dc:date>2017-04-18T13:47:42Z</dc:date>
    </item>
  </channel>
</rss>

