<?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 How to set time span in relative terms? in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252587#M189342</link>
    <description>&lt;P&gt;I have a form where I accept two inputs: a phone number and a time picker for the search. I need to make a search for this phone number in the selected period. Than I need to make one more search (with a join) with a different query for the same phone number but with a different time range: if the first search was made on day x (meaning the user selected day x on time picker), I need the search inside the join to be made on &lt;STRONG&gt;day x to day x+2&lt;/STRONG&gt;. I cannot find out a way to get this. &lt;BR /&gt;
I tried using relative_time() function, but you cannot use it for evaluating "latest" parameter. So I tried defining a macro (found something about that here), but whatever I try I get the usual (meaningless) error "The definition of macro is expected to be an eval expression that returns a string". &lt;BR /&gt;
Any way to get this? This is my (simplified) query&lt;/P&gt;

&lt;P&gt;index=xxx sourcetype="log4j" dstphonenumber =$f_mobileNum$  earliest=$f_time.earliest$ latest=$f_time.latest$ |     join type=left smsid  [search index=xxx smslogprefix=SOMEVALUE dstphonenumber=$f_mobileNum$ earliest=$f_time.earliest$ latest=WHAT TO PUT HERE?   ]&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 09:08:20 GMT</pubDate>
    <dc:creator>ggillini</dc:creator>
    <dc:date>2020-09-29T09:08:20Z</dc:date>
    <item>
      <title>How to set time span in relative terms?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252587#M189342</link>
      <description>&lt;P&gt;I have a form where I accept two inputs: a phone number and a time picker for the search. I need to make a search for this phone number in the selected period. Than I need to make one more search (with a join) with a different query for the same phone number but with a different time range: if the first search was made on day x (meaning the user selected day x on time picker), I need the search inside the join to be made on &lt;STRONG&gt;day x to day x+2&lt;/STRONG&gt;. I cannot find out a way to get this. &lt;BR /&gt;
I tried using relative_time() function, but you cannot use it for evaluating "latest" parameter. So I tried defining a macro (found something about that here), but whatever I try I get the usual (meaningless) error "The definition of macro is expected to be an eval expression that returns a string". &lt;BR /&gt;
Any way to get this? This is my (simplified) query&lt;/P&gt;

&lt;P&gt;index=xxx sourcetype="log4j" dstphonenumber =$f_mobileNum$  earliest=$f_time.earliest$ latest=$f_time.latest$ |     join type=left smsid  [search index=xxx smslogprefix=SOMEVALUE dstphonenumber=$f_mobileNum$ earliest=$f_time.earliest$ latest=WHAT TO PUT HERE?   ]&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 09:08:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252587#M189342</guid>
      <dc:creator>ggillini</dc:creator>
      <dc:date>2020-09-29T09:08:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to set time span in relative terms?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252588#M189343</link>
      <description>&lt;P&gt;Try something like this  (the subsearch inside the join subsearch is updating the earliest and latest for the join subsearch)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;&amp;lt;search&amp;gt;
          &amp;lt;query&amp;gt;
        index=xxx sourcetype="log4j" dstphonenumber =$f_mobileNum$   | join type=left smsid [search index=xxx smslogprefix=SOMEVALUE dstphonenumber=$f_mobileNum$ [| gentimes start=-1 | addinfo | eval earliest=info_min_time | eval latest=relative_time(info_min_time,"+2d") | table earliest latest | format "" "" "" "" "" ""] ] | .....rest of the commands...
          &amp;lt;/query&amp;gt;
            &amp;lt;earliest&amp;gt;$f_time.earliest$&amp;lt;/earliest&amp;gt;
            &amp;lt;latest&amp;gt;$f_time.latest$&amp;lt;/latest&amp;gt;
&amp;lt;/search&amp;gt;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Mar 2016 19:51:42 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252588#M189343</guid>
      <dc:creator>somesoni2</dc:creator>
      <dc:date>2016-03-18T19:51:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to set time span in relative terms?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252589#M189344</link>
      <description>&lt;P&gt;Thanks for your answer. First of all, with your query I don't get any more errors, and this is ok. Then I need to check if this does what I want, and eventually I will need to understand what it's actually doing, But it is a good start at least &lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 16:25:13 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252589#M189344</guid>
      <dc:creator>ggillini</dc:creator>
      <dc:date>2016-03-21T16:25:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to set time span in relative terms?</title>
      <link>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252590#M189345</link>
      <description>&lt;P&gt;Unfortunately it looks like your answer doesn't solve my problem.&lt;BR /&gt;
The matter is how gentimes command works. In the way you wrote it, it ALWAYS starts from yesterday, so my search will get up to end on today + 2 days. I need to have earliest time equal to the one on the main search, and latest time equal to the one on the main search +2 days.&lt;BR /&gt;
This means I cannot use a constant in input to gentimes, like you did. I tried using the value of the choice made by the user, but it's not accepted as it is in "time picker" format (a string like '-1d@d'), and it looks like that format is not accepted in a different context.&lt;BR /&gt;
What it seems to me is that Splunk is quite inconsistent in the way it allows timestamps and time-related values, in general, to be manipulated in different contexts.&lt;/P&gt;</description>
      <pubDate>Thu, 31 Mar 2016 13:26:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/How-to-set-time-span-in-relative-terms/m-p/252590#M189345</guid>
      <dc:creator>ggillini</dc:creator>
      <dc:date>2016-03-31T13:26:55Z</dc:date>
    </item>
  </channel>
</rss>

